This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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(j&i){
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |