# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
170033 | tselmegkh | Bank (IZhO14_bank) | C++14 | 1085 ms | 532 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>
using namespace std;
int a[25], b[25], n, m;
bool dp[25][(1 << 21)];
bool vis[25][(1 << 21)];
bool go(int v, int mask){
if(v == n){
return 1;
}
if(vis[v][mask])return dp[v][mask];
vis[v][mask] = 1;
bool possible = 0;
for(int i = 0; i < (1 << m); i++){
int sum = 0;
bool ok = 1;
for(int j = 0; j < m; j++){
if(((1 << j) & i)){
sum += b[j];
}
}
if(sum == a[v] && !(i & mask)){
possible |= go(v + 1, mask | i);
}
}
return dp[v][mask] = possible;
}
int main(){
cin >> n >> m;
for(int i = 0; i < n; i++){
cin >> a[i];
}
for(int i = 0; i < m; i++){
cin >> b[i];
}
if(go(0, 0)){
cout << "YES\n";
}else{
cout << "NO\n";
}
}
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... |