제출 #813659

#제출 시각아이디문제언어결과실행 시간메모리
813659exodus_은행 (IZhO14_bank)C++14
100 / 100
168 ms6068 KiB
#include<bits/stdc++.h> using namespace std; int N,M; vector<int>sum[21]; vector<vector<bool>>memo(21, vector<bool>(1<<20)); vector<vector<bool>>visited(21, vector<bool>(1<<20, false)); int pip[21]; bool dp(int idx, int mask) { bool fin=false; if(idx > N-1) { return true; } if(visited[idx][mask]==true) { return memo[idx][mask]; } visited[idx][mask]=true; for(auto x:sum[idx]) { if((x & mask) == 0) { if(dp(idx+1, (x|mask)) == true) { fin = true; break; } } } memo[idx][mask]=fin; return fin; } int main() { cin >> N >> M; vector<int>vek(M); for(int i=0; i<N; i++) { cin >> pip[i]; } for(int i=0; i<M; i++) { cin >> vek[i]; } for(int mask=0; mask<(1<<M); mask++) { int sm=0; for(int k=0; k<M; k++) { int tmp = (mask>>k)&1; if(tmp) sm+=vek[k]; } for(int i=0; i<N; i++) { if(sm==pip[i]) sum[i].emplace_back(mask); } } bool can = dp(0,0); if(can) cout << "YES"; else cout << "NO"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...