Submission #997307

#TimeUsernameProblemLanguageResultExecution timeMemory
997307MarszpaceBank (IZhO14_bank)C++14
71 / 100
1083 ms86872 KiB
/* * With a little appreciation, in a mostly hollow tone, she says, "Delightful." As if the world has any meaning. * TASK : Bank * AUTHOR : Marszpace */ #include<bits/stdc++.h> using namespace std; int n,m; vector<int> ppl(20); vector<int> notes(20); vector<vector<int>> dp(20,vector<int>((1<<20),2)); bool recur(int p, int s){ //cout << p << " " << s << endl; if(p==n){return true;} if(dp[p][s]!=2){return dp[p][s];} for(int nexts=0;nexts<(1<<m);nexts++){ if((nexts|s)!=nexts){continue;} int val=0; for(int i=0;i<m;i++){ if((s&(1<<i))==0&&(nexts&(1<<i))==(1<<i)){ val+=notes[i]; } } if(val==ppl[p]){ bool res=recur(p+1,nexts); if(res){dp[p][s]=1;return true;} } } dp[p][s]=0; return false; } int main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin >> n >> m; for(int i=0;i<n;i++){ cin >> ppl[i]; } for(int i=0;i<m;i++){ cin >> notes[i]; } cout << (recur(0,0)?"YES":"NO"); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...