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;
int N,M;
vector<int>sum[21];
vector<vector<bool>>memo(21, vector<bool>(1<<20));
vector<vector<bool>>visited(21, vector<bool>(1<<20, false));
int pip[21];
bool dp(int idx, int mask) {
bool fin=false;
if(idx > N-1) {
return true;
}
if(visited[idx][mask]==true) {
return memo[idx][mask];
}
for(auto x:sum[idx]) {
if((x & mask) == 0) {
if(dp(idx+1, (x|mask)) == true) {
fin = true;
break;
}
}
}
memo[idx][mask]=fin;
return fin;
}
int main() {
cin >> N >> M;
vector<int>vek(M);
for(int i=0; i<N; i++) {
cin >> pip[i];
}
for(int i=0; i<M; i++) {
cin >> vek[i];
}
for(int mask=0; mask<(1<<M); mask++) {
int sm=0;
for(int k=0; k<M; k++) {
int tmp = (mask>>k)&1;
if(tmp) sm+=vek[k];
}
for(int i=0; i<N; i++) {
if(sm==pip[i]) sum[i].emplace_back(mask);
}
}
bool can = dp(0,0);
if(can) cout << "YES"; else cout << "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... |