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;
const int mx=30;
typedef long long ll;
int inf=1e9+10;
const int mod=1e9+7;
int a[30];
int b[30];
int x[mx];
int n,m;
vector<int>sums[20005];
map<int,int>mp;
int dp[21][(1<<20)+2];
int solve(int i,int mask){
if(i==n){
return 1;
}
int &ret=dp[i][mask];
if(ret!=-1){
return ret;
}
ret=0;
for(auto it:sums[a[i]]){
if((it&mask)==it){
ret=max(solve(i+1,mask^it),ret);
}
}
return ret;
}
int main(){
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<m;i++){
cin>>b[i];
}
for(int i=0;i<(1<<m);i++){
int sum=0;
for(int j=0;j<m;j++){
if(i&(1<<j)){
sum+=b[j];
}
}
sums[sum].push_back(i);
}
memset(dp,-1,sizeof(dp));
// cout<<sums[3][0];
if(solve(0,(1<<m)-1)){
cout<<"YES";
}else{
cout<<"NO";
}
}
# | 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... |