Submission #677978

#TimeUsernameProblemLanguageResultExecution timeMemory
677978Ahmed57Bank (IZhO14_bank)C++14
100 / 100
257 ms90260 KiB
#include <bits/stdc++.h> using namespace std; vector<int> v[20001]; int n,m;int ob[20],su[20]; int dp[20][(1<<20)]; int solve(int i,int mask){ if(i==n){ return 1; } if(dp[i][mask]!=-1)return dp[i][mask]; int ans = 0; for(auto j:v[ob[i]]){ if((j&mask)==0){ ans|=solve(i+1,(mask|j)); if(ans==1)break; } } return dp[i][mask] = ans; } 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>>ob[i]; for(int i = 0;i<m;i++)cin>>su[i]; for(int mask = 1;mask<(1<<m);mask++){ long long sum = 0; for(int j = 0;j<m;j++){ if(mask&(1<<j))sum+=su[j]; } v[sum].push_back(mask); } memset(dp,-1,sizeof dp); cout<<(solve(0,0)?"YES\n":"NO\n"); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...