Submission #859553

#TimeUsernameProblemLanguageResultExecution timeMemory
859553overwatch9Bank (IZhO14_bank)C++17
100 / 100
798 ms34224 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; const int maxn = 20; const int maxm = 20; const int maxmask = (1 << maxm) + 1; vector <int> works[maxn]; vector <int> notes; int n, m; void solve(int sum, int mask, int id) { vector <int> nums(__builtin_popcount(mask)); int s = 0; for (int i = 0; i < m; i++) { if (mask & (1 << i)) s += notes[i]; if (s > sum) break; } if (sum == s) works[id].push_back(mask); } bool dp[maxn][maxmask]; bool ready[maxn][maxmask]; bool solve2(int i, int mask) { if (i == n) return true; if (ready[i][mask]) return dp[i][mask]; bool ans = false; for (auto j : works[i]) { if ((mask & j) == j) ans |= solve2(i+1, mask ^ j); } ready[i][mask] = true; dp[i][mask] = ans; return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; vector <int> sums(n); notes.resize(m); for (int i = 0; i < n; i++) cin >> sums[i]; for (int i = 0; i < m; i++) { cin >> notes[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < (1 << m); j++) solve(sums[i], j, i); } if (solve2(0, (1 << m) - 1)) cout << "YES\n"; else 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...