제출 #922591

#제출 시각아이디문제언어결과실행 시간메모리
922591THXuan은행 (IZhO14_bank)C++14
100 / 100
362 ms15444 KiB
// dp[i][mask] = true if the first i-th person is considered and the on bit in mask is taken // base case dp[0][0] = true; #include <bits/stdc++.h> #define INF 1e9 using namespace std; typedef long long ll; bool dp[30][2000000]; vector<int>val[30]; void solve() { int n, m; cin >> n >> m; vector<int>a(n + 1), b(m + 1); for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= m; i++) cin >> b[i]; for (int mask = 0; mask < (1 << m); mask++) { int sum = 0; for (int i = 0; i < m; i++) { if (mask & (1 << i))sum += b[i + 1]; } for (int i = 1; i <= n; i++) { if (a[i] == sum) val[i].push_back(mask); } } dp[0][0] = true; for (int i = 0; i < n; i++) { for (int mask = 0; mask < (1 << m); mask++) { if (!dp[i][mask]) continue; for (auto u : val[i + 1]) { if ((mask & u) == 0) dp[i + 1][mask | u] |= dp[i][mask]; } } } for (int mask = 0; mask < (1 << m); mask++) { if (dp[n][mask]) { cout << "YES" << "\n"; return; } } cout << "NO" << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1;// cin>>t; while (t--) solve(); 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...