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 int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
//#define endl '\n'
int n,m;
int dp[21][1<<20];
int aa[21];
int bb[21];
int su[1<<20];
vector<int> pre[1<<20];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>aa[i];
}
for(int i=0;i<m;i++){
cin>>bb[i];
}
for(int j=0;j<(1<<m);j++){
for(int k=0;k<m;k++){
if((1<<k)&j){
su[j]=su[j-(1<<k)]+bb[k];
break;
}
}
for(int i=0;i<n;i++){
if(aa[i]==su[j]){
pre[i].pb(j);
}
}
}
for(int j=0;j<(1<<m);j++){
dp[n][j]=1;
}
for(int i=n-1;i>=0;i--){
for(int j=0;j<(1<<m);j++){
for(auto k:pre[i]){
if((k&j)==k){
dp[i][j]|=dp[i+1][j-k];
if(dp[i][j]==1){
break;
}
}
}
}
}
if(dp[0][(1<<m)-1]){
cout<<"YES"<<endl;
}
else{
cout<<"NO"<<endl;
}
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... |