Submission #595899

#TimeUsernameProblemLanguageResultExecution timeMemory
595899BelphegorBank (IZhO14_bank)C++14
25 / 100
114 ms22896 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; int n,m; int A[11],B[11]; char dp[11][1005][(1<<10)]; char f(int cur,int k,int state){ char&ret = dp[cur][k][state]; if(~ret) return ret; ret = 0; if(cur==n) return ret = 1; if(!k) return ret = f(cur+1,A[cur+1],state); for(int i=0; i<m; i++){ if(state&(1<<i)){ if(k>=B[i]) ret|=f(cur,k-B[i],state^(1<<i)); } } return ret; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); 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)); cout<<(f(0,A[0],(1<<m)-1)?"YES":"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...