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 <vector>
#include <algorithm>
using namespace std;
const int maxn = 20;
const int maxm = 20;
const int maxmask = (1 << maxm) + 1;
vector <int> works[maxn];
vector <int> notes;
int n, m;
void solve(int sum, int mask, int id) {
vector <int> nums(__builtin_popcount(mask));
int s = 0;
for (int i = 0; i < m; i++) {
if (mask & (1 << i))
s += notes[i];
if (s > sum)
break;
}
if (sum == s)
works[id].push_back(mask);
}
bool dp[maxn][maxmask];
bool ready[maxn][maxmask];
bool solve2(int i, int mask) {
if (i == n)
return true;
if (ready[i][mask])
return dp[i][mask];
bool ans = false;
for (auto j : works[i]) {
if ((mask & j) == j)
ans |= solve2(i+1, mask ^ j);
}
ready[i][mask] = true;
dp[i][mask] = ans;
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
vector <int> sums(n);
notes.resize(m);
for (int i = 0; i < n; i++)
cin >> sums[i];
for (int i = 0; i < m; i++) {
cin >> notes[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < (1 << m); j++)
solve(sums[i], j, i);
}
if (solve2(0, (1 << m) - 1))
cout << "YES\n";
else
cout << "NO\n";
}
# | 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... |