# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
91118 | Hideo | Bank (IZhO14_bank) | C++14 | 1076 ms | 4568 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define mk make_pair
using namespace std;
const int N = 25;
int dp[N][1 << 16], a[N], b[N], sum[1 << 16];
int n, m;
main(){
cin >> n >> m;
for (int i = 1; i <= n; i++){
scanf ("%d", &a[i]);
}
for (int i = 1; i <= m; i++){
scanf ("%d", &b[i]);
}
for (int mask = 0; mask < (1 << m); mask++){
for (int i = 1; i <= m; i++){
if (mask & (1 << (i - 1))){
sum[mask] += b[i];
}
}
}
dp[0][0] = 1;
for (int i = 1; i <= n; i++){
for (int mask1 = 0; mask1 < (1 << m); mask1++){
for (int mask2 = mask1; mask2 > 0; mask2 = mask1 & (mask2 - 1)){
if (dp[i - 1][mask1 - mask2] == 1 && sum[mask2] == a[i]){
dp[i][mask1] = 1;
break;
}
}
}
}
for (int mask = 0; mask < (1 << m); mask++){
if (dp[n][mask]){
cout << "YES";
return 0;
}
}
cout << "NO";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |