結果
| 問題 |
No.115 遠足のおやつ
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2018-10-05 16:58:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 10 ms / 5,000 ms |
| コード長 | 687 bytes |
| コンパイル時間 | 1,657 ms |
| コンパイル使用メモリ | 159,344 KB |
| 実行使用メモリ | 12,416 KB |
| 最終ジャッジ日時 | 2025-01-03 01:31:09 |
| 合計ジャッジ時間 | 2,998 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
Int n,d,k;
Int dp[101][1010][11];
Int dfs(Int x,Int y,Int z){
Int &res=dp[x][y][z];
if(~res) return res;
if(x==n) return res=(y==d&&z==k);
res=0;
res|=dfs(x+1,y,z);
if(y+(x+1)<=d&&z+1<=k) res|=dfs(x+1,y+(x+1),z+1);
return res;
}
void dfs2(Int x,Int y,Int z){
if(x==n) return;
if(y+(x+1)<=d&&z+1<=k&&dfs(x+1,y+(x+1),z+1)){
if(y) cout<<" ";
cout<<x+1;
dfs2(x+1,y+(x+1),z+1);
return;
}
dfs2(x+1,y,z);
}
signed main(){
cin>>n>>d>>k;
memset(dp,-1,sizeof(dp));
if(!dfs(0,0,0)){
cout<<-1<<endl;
return 0;
}
dfs2(0,0,0);
cout<<endl;
return 0;
}
beet