Submission #360404

#TimeUsernameProblemLanguageResultExecution timeMemory
360404SeanliuBank (IZhO14_bank)C++14
52 / 100
1085 ms8684 KiB
#include <iostream> #include <algorithm> using namespace std; const int maxN = 21; int N, M, a[maxN], b[maxN], dp[maxN][1 << maxN], has[maxN], head, cnt; bool dfs(int now, int cursum, int tgt, int &curmask, int &ind){ //cout << "running dfs(" << now << ", " <<cursum << ", " << tgt << ", " << curmask << ", " << ind << ")\n"; if(cursum == tgt){ return dp[ind - 1][curmask]; } if(now >= head) return false; if(tgt - cursum < b[has[now]]) return false; curmask ^= (1 << has[now]); if(dfs(now + 1, cursum + b[has[now]], tgt, curmask, ind)){ curmask ^= (1 << has[now]); return true; } curmask ^= (1 << has[now]); if(dfs(now + 1, cursum, tgt, curmask, ind)){ return true; } return false; } int main(){ cin >> N >> M; for(int i = 1; i <= N; i++) cin >> a[i]; for(int i = 0; i < M; i++) cin >> b[i]; sort(b, b + M); for(int m = 0; m < (1 << M); m++) dp[0][m] = 1; for(int i = 1; i <= N; i++){ for(int m = 0; m < (1 << M); m++){ //cout << "Running " << i << " " << m << endl; head = 0; cnt = 0; for(int j = 0; j < M; j++) if(((m >> j) & 1)) has[head++] = j; dp[i][m] = dfs(0, 0, a[i], m, i); //cout << "done" << endl; } } for(int m = 0; m < (1 << M); m++) if(dp[N][m]){ cout << "YES\n"; return 0; } cout << "NO\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...