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;
typedef pair<int,int> point;
#define Rd(r) freopen(r, "r", stdin);
#define Wt(w) freopen(w, "w", stdout);
#define x first
#define y second
#define INF 1<<30
#define MAXI 20
vector<int> MASK[MAXI];
int dp[1 << MAXI], rem[1 << MAXI], mark[1 << MAXI], y;
bool flag = false;
bool ZiwenZapper(int n, int m, int a[], int b[]) {
y = 0;
mark[0] = 1;
for(int mask = 0; mask < (1 << m); mask++){
for(int i = 0; i < m; i++){
if(mark[mask ^ (1 << i)] and (mask & (1 << i))){
int last = dp[mask ^ (1 << i)];
int curr = rem[mask ^ (1 << i)] + b[i];
if(curr > a[last]) continue;
dp[mask] = last + (curr == a[last] ? 1 : 0);
rem[mask] = (curr == a[last] ? 0 : curr);
mark[mask] = 1;
}
}
if(dp[mask] == n) y = 1;
}
return y ? true : false;
}
int main()
{
//Rd("ziwenzapper.in");
int n, m;
int a[MAXI], b[MAXI];
cin >> m >> n;
for (int i = 0; i < m; i++) cin >> b[i];
for (int j = 0; j < n; j++) cin >> a[j];
bool val = ZiwenZapper(m, n, b, a);
cout << (val ? "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... |