Submission #420351

#TimeUsernameProblemLanguageResultExecution timeMemory
420351Runtime_error_Bank (IZhO14_bank)C++14
19 / 100
137 ms172716 KiB
#include <bits/stdc++.h> #define pb push_back using namespace std; const int inf = 21; int a[inf],b[inf],n,m; int dp[inf][(1<<inf)]; int solve(int salary,int mask){ if(salary == n) return 1; int &ret = dp[salary][mask]; if(ret != -1) return ret; ret = 0; vector<int> coins; for(int j=0;j<m;j++) if(!(mask & (1<<j))) coins.pb(b[j]); int cur = coins.size(); for(int i=0;i<(1<<cur);i++){ int sum = 0; for(int j=0;j<cur;j++) if(i & (1<<j)) sum += coins[j]; if(sum == a[salary]) ret |= solve(salary+1,mask|i); } 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]; memset(dp,-1,sizeof(dp)); int ans = solve(0,0); if(ans) puts("YES"); else puts("NO"); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...