제출 #919679

#제출 시각아이디문제언어결과실행 시간메모리
919679dubabuba은행 (IZhO14_bank)C++14
100 / 100
97 ms186704 KiB
#include <bits/stdc++.h> using namespace std; const int mxn = 21; const int mxa = 1010; vector<int> bit[mxa * mxn]; int sum[1 << mxn]; int n, a[mxn]; int m, b[mxn]; int dp[mxn][1 << mxn]; int solve(int i, int cur) { if(i == 0) return 1; if(dp[i][cur] > -1) return dp[i][cur]; int &val = a[i]; dp[i][cur] = 0; for(int las : bit[val]) { if(((cur | las) == cur) && solve(i - 1, cur ^ las)) dp[i][cur] = 1; } return dp[i][cur]; } int main() { cin >> n >> m; for(int i = 1; i <= n; i++) cin >> a[i]; for(int j = 0; j < m; j++) cin >> b[j]; for(int cur = 0; cur < (1 << m); cur++) { int sus, prv; for(sus = 0; sus < m; sus++) if(cur & (1 << sus)) break; prv = cur ^ (1 << sus); sum[cur] = sum[prv] + b[sus]; bit[sum[cur]].push_back(cur); } memset(dp, -1, sizeof dp); if(solve(n, (1 << m) - 1)) cout << "YES\n"; else cout << "NO\n"; 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...