Submission #41236

#TimeUsernameProblemLanguageResultExecution timeMemory
41236IvanCBank (IZhO14_bank)C++14
100 / 100
298 ms90096 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 20; const int MAXV = 1001; const int MAXL = (1 << 20); vector<int> possiveis[MAXN*MAXV]; int dp[MAXN][MAXL],n,m,vetor[MAXN],obj[MAXN]; int solve(int pos,int bitmask){ if(pos == n) return 1; if(dp[pos][bitmask] != -1) return dp[pos][bitmask]; for(int mascara : possiveis[vetor[pos]]){ if(!(mascara & bitmask)){ if(solve(pos+1,bitmask | mascara )) return dp[pos][bitmask] = 1; } } return dp[pos][bitmask] = 0; } void brute(int pos,int bitmask,int val){ if(pos == m){ possiveis[val].push_back(bitmask); return; } brute(pos+1,bitmask,val); brute(pos+1,bitmask | (1 << pos), val + obj[pos] ); } int main(){ cin >> n >> m; for(int i = 0;i<n;i++) cin >> vetor[i]; for(int i = 0;i<m;i++) cin >> obj[i]; brute(0,0,0); memset(dp,-1,sizeof(dp)); if(solve(0,0)) printf("YES\n"); else printf("NO\n"); 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...