Submission #1014685

#TimeUsernameProblemLanguageResultExecution timeMemory
1014685MMihalevBank (IZhO14_bank)C++14
100 / 100
147 ms8828 KiB
#include<iostream> #include<algorithm> #include<iomanip> #include<cmath> #include<cstring> #include<vector> #include<queue> #include<stack> #include<tuple> #include<set> #include<map> #include<random> #include<chrono> using namespace std; const int MAX_N=20; int dp[(1<<MAX_N)]; int leftt[(1<<MAX_N)]; int cost[(1<<MAX_N)]; int n,m; int a[MAX_N]; int b[MAX_N]; signed main () { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.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]; } dp[0]=-1; for(int mask=1;mask<(1<<m);mask++) { dp[mask]=-1; for(int bit=0;bit<m;bit++) { if(((1<<bit)&mask)!=0) { leftt[mask]+=b[bit]; } } } for(int mask=1;mask<(1<<m);mask++) { for(int bit=0;bit<m;bit++) { if(((1<<bit)&mask)!=0) { if(dp[mask & ~(1<<bit)]>dp[mask]) { dp[mask]=dp[mask & ~(1<<bit)]; leftt[mask]=leftt[mask & ~(1<<bit)]+b[bit]; } if(leftt[mask & ~(1<<bit)]+b[bit]==a[dp[mask & ~(1<<bit)]+1]) { if(dp[mask & ~(1<<bit)]+1>dp[mask]) { dp[mask]=dp[mask & ~(1<<bit)]+1; leftt[mask]=0; } } } } } if(dp[(1<<m)-1]==n-1)cout<<"YES\n"; else cout<<"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...