제출 #361670

#제출 시각아이디문제언어결과실행 시간메모리
361670ngpin04은행 (IZhO14_bank)C++14
100 / 100
469 ms26292 KiB
#include <bits/stdc++.h> using namespace std; int a[21]; int b[20]; int sum[1 << 20]; int n,m; bool dp[1 << 20][21]; int getbit(int x, int i) { return (x >> i) & 1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); //freopen("bank.in","r",stdin); //freopen("bank.out","w",stdout); cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i], a[i] += a[i - 1]; 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 (getbit(mask, i)) sum[mask] += b[i]; dp[0][0] = true; for (int mask = 0; mask < (1 << m); mask++) for (int i = 0; i <= n; i++) if (dp[mask][i]) { if (sum[mask] == a[i]) { if (i == n) return cout << "YES\n", 0; dp[mask][i + 1] = true; } else { for (int j = 0; j < m; j++) if (!getbit(mask, j)) dp[mask | (1 << j)][i] = true; } } 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...