Submission #76748

#TimeUsernameProblemLanguageResultExecution timeMemory
76748szawinisBank (IZhO14_bank)C++17
100 / 100
215 ms19068 KiB
#include <bits/stdc++.h> using namespace std; int n, m, a[20], b[20], sum[1 << 20]; vector<int> states[20]; bool vis[20][1 << 20], dp[20][1 << 20]; bool solve(int idx, int mask) { if(idx == n) return true; if(vis[idx][mask]) return dp[idx][mask]; vis[idx][mask] = true; for(int nxt: states[idx]) { if((nxt & mask) == 0 && solve(idx + 1, nxt | mask)) return dp[idx][mask] = true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < m; i++) cin >> b[i]; for(int mask = 0; mask < 1 << m; mask++) { for(int i = 0; i < m; i++) if(mask >> i & 1) sum[mask] += b[i]; for(int i = 0; i < n; i++) if(sum[mask] == a[i]) states[i].push_back(mask); } if(solve(0, 0)) cout << "YES" << endl; else cout << "NO" << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...