제출 #961589

#제출 시각아이디문제언어결과실행 시간메모리
961589blacktulip은행 (IZhO14_bank)C++17
71 / 100
1050 ms172892 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define fi first #define se second const int li=21; int n,m,a[li],b[li],dp[li][(1<<20)]; inline int f(int sira,int mask){ int cevv=0; if(sira>n)return 1; if(~dp[sira][mask])return dp[sira][mask]; vector<int> v; for(int i=0;i<m;i++){ if(mask&(1<<i))continue; v.pb(i); } int siz=v.size(); for(int i=0;i<(1<<siz);i++){ int sum=0; int mask2=0; for(int j=0;j<siz;j++){ if(i&(1<<j)){ sum+=b[v[j]]; mask2|=(1<<v[j]); } } //~ cout<<sum<<" () "<<sira<<" () "<<i<<endl; if(sum==a[sira])cevv=max(cevv,f(sira+1,mask|mask2)); } return dp[sira][mask]=cevv; } int32_t main(){ cin>>n>>m; memset(dp,-1,sizeof(dp)); for(int i=1;i<=n;i++)cin>>a[i]; for(int i=0;i<m;i++)cin>>b[i]; int cev=f(1,0); if(cev)cout<<"YES\n"; else cout<<"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...