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>
#define pb push_back
using namespace std;
const int inf = 21;
int a[inf],b[inf],n,m;
int dp[inf][(1<<inf)];
int solve(int salary,int mask){
if(salary == n)
return 1;
int &ret = dp[salary][mask];
if(ret != -1)
return ret;
ret = 0;
vector<int> coins;
for(int j=0;j<m;j++)
if(!(mask & (1<<j)))
coins.pb(b[j]);
int cur = coins.size();
for(int i=0;i<(1<<cur);i++){
int sum = 0;
for(int j=0;j<cur;j++)
if(i & (1<<j))
sum += coins[j];
if(sum == a[salary])
ret |= solve(salary+1,mask|i);
}
return ret;
}
int main(){
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));
int ans = solve(0,0);
if(ans)
puts("YES");
else puts("NO");
}
# | 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... |