This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifdef LOCAL
#include <local.h>
#else
#include <bits/stdc++.h>
#define debug(...)
#endif
const int maxn = 20;
int n, m;
int a[maxn];
int b[maxn];
int dp[1 << maxn];
int go(int i, int mask, int sum) {
if (i >= n) return true;
int &ret = dp[mask];
if (ret != -1) return ret;
for (int j = 0; j < m; j++) {
if (mask >> j & 1) continue;
if (sum + b[j] == a[i]) {
if (go(i + 1, mask | (1 << j), 0)) {
return ret = true;
}
}
else if (sum + b[j] < a[i]) {
if (go(i, mask | (1 << j), sum + b[j])) {
return ret = true;
}
}
}
return ret = false;
}
signed main() {
std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr);
std::cin >> n >> m;
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
for (int i = 0; i < m; i++) {
std::cin >> b[i];
}
std::fill_n(dp, 1 << maxn, -1);
std::cout << (go(0, 0, 0) ? "YES" : "NO") << '\n';
return 0;
}
# | 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... |