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 mxn=25, inf=1e9+10;
int n, m;
int A[mxn], B[mxn];
int dp[mxn][(1<<20)+10];
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];
memset(dp, -1, sizeof(dp));
//estou criando o elemento 0 com mask0 elementos
dp[0][0]=0;
for(int i=0; i<n; i++){ //pra cada prole
for(int mask=0; mask<(1<<m); mask++){ //maskaras das banknotes
if(dp[i][mask]==-1) continue;
for(int j=0; j<m; j++){
if(mask&(1<<j)) continue; //pra cada banknote não acessa
if(dp[i][mask] + B[j] == A[i])
dp[i+1][mask|(1<<j)]=0;
else
dp[i][mask|(1<<j)]=dp[i][mask]+B[j];
}
}
}
bool ans=false;
for(int mask=0; mask<(1<<m); mask++)
if(dp[n][mask]!=-1){
ans=true;
//cout<<mask<<endl;
}
cout<<(ans?"YES":"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... |