제출 #76746

#제출 시각아이디문제언어결과실행 시간메모리
76746szawinis은행 (IZhO14_bank)C++17
19 / 100
74 ms4736 KiB
#include <bits/stdc++.h> using namespace std; int n, m, a[20], b[20], sum[1 << 20]; vector<int> states[20]; int curr[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...