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 N =20;
const int M =21;
//前m个banknote, N
int dp[M][1<<N];
int salary[N];
int banknote[M];
int main(){
int n, m;
cin>>n>>m;
for(int i=0;i<n;i++)
cin>>salary[i];
for(int i=0;i<m;i++)
cin>>banknote[i];
for(int i=0;i<=m;i++)
dp[i][0] = 1;
for(int s=1;s<(1<<n);s++ ){
for(int bk=1;bk<=m;bk++){
dp[bk][s] = dp[bk-1][s];
for(int p=0;p<n;p++){
//cout<<'p'<<p<<'\n';
if((s&(1<<p))==0)
continue;
int ind = bk-1;
int sum = 0;
while(sum < salary[p] && ind>=0){
sum += banknote[ind];
ind--;
}
if(ind<0 || sum != salary[p]){
continue;
}
ind++;
//cout<<"now "<<bk<<' '<<bitset<5>(s)<<' '<<bitset<5>(s^(1<<p))<<' '<<(ind-1)<<' '<<dp[ind][s^(1<<p)]<<'\n';
dp[bk][s] = max(dp[bk][s], dp[ind][s^(1<<p)]);
}
}
}
if(dp[m][(1<<n)-1])
cout<<"YES\n";
else
cout<<"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... |