Submission #21012
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include<bits/stdc++.h> using namespace std; int n,k,a[25],memo[25][26]; bool f( int idx, int sum); main(){ cin>>n>>k; for ( int i=0;i<n;i++){ cin>>a[i]; a[i]*=-1; } if (f(0,0))cout<< "OK" <<endl; else cout<< "NG" <<endl; } bool f( int idx, int sum){ if (idx==n){ if (sum==k) return true ; else return false ; } if (sum>k) return false ; if (memo[idx][sum]) return false ; if (f(idx+1,sum)) return true ; if (f(idx+1,sum+a[idx])) return true ; memo[idx][sum]=1; return false ; } |
ステータス
項目 | データ |
---|---|
問題 | 0491 - 印刷ミス |
ユーザー名 | ei1516 |
投稿日時 | 2017-07-07 17:33:43 |
言語 | C++11 |
状態 | Accepted |
得点 | 1 |
ソースコード長 | 517 Byte |
最大実行時間 | 47 ms |
最大メモリ使用量 | 652 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 1 / 1 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
input1.txt | AC | 47 ms | 608 KB |
1
|
input2.txt | AC | 43 ms | 580 KB |
1
|
input3.txt | AC | 29 ms | 552 KB |
1
|
input4.txt | AC | 20 ms | 652 KB |
1
|