제출 #961601

#제출 시각아이디문제언어결과실행 시간메모리
961601blacktulip은행 (IZhO14_bank)C++17
19 / 100
79 ms86872 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){cout<<"YES\n";exit(0);} 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)); break; } } return dp[sira][mask]=cevv; } int 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...