# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1076962 | xnqs | Bank (IZhO14_bank) | C++17 | 67 ms | 20928 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 <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <cstring>
int tgt_cnt, x;
int tgt[25];
int arr[25];
char dp[20][1<<20];
bool sol(int pos, int mask) {
if (pos==tgt_cnt) {
return 1;
}
if (dp[pos][mask]!=-1) {
return dp[pos][mask];
}
bool ret = 0;
for (int mask2 = 0; mask2 < (1<<x); mask2++) {
if (mask2&mask) {
continue;
}
int sum = 0;
for (int i = 0; i < x; i++) {
if (mask2&(1<<i)) {
sum += arr[i];
}
if (sum>tgt[pos]) {
goto gtfo;
}
}
if (sum==tgt[pos]) {
ret |= sol(pos+1,mask|mask2);
break;
}
gtfo:
continue;
}
return dp[pos][mask] = ret;
}
int main() {
std::cin >> tgt_cnt >> x;
for (int i = 0; i < tgt_cnt; i++) {
std::cin >> tgt[i];
}
for (int i = 0; i < x; i++) {
std::cin >> arr[i];
}
memset(dp,-1,sizeof(dp));
std::cout << ((sol(0,0)) ? "YES" : "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... |