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;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
const int maxn = 22;
int n, m;
int a[maxn];
int b[maxn];
bool dp[maxn][1<<20];
int sum[1<<20];
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>m;
for (int i=1; i<=n; i++) {
cin>>a[i];
}
for (int i=1; i<=m; i++) {
cin>>b[i];
}
for (int mask=0; mask<1<<m; mask++) {
for (int j=0; j<m; j++) {
if (mask>>j&1) sum[mask] += b[j];
}
}
for (int mask=0; mask<1<<m; mask++) {
dp[0][mask]=true;
}
for (int i=1; i<=n; i++) {
for (int mask=0; mask<1<<m; mask++) {
for (int s=mask; ;s=((s-1)&mask)) {
if (dp[i-1][s] && sum[mask^s]==a[i]) {
dp[i][mask]=true;
}
if (s==0) break;
}
}
}
for (int mask=0; mask<1<<m; mask++) {
if (dp[n][mask]) out("YES");
}
out("NO");
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... |