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;
typedef long long ll;
# define int long long
# define For(i, n) for(int i=0; i<n; i++)
# define Fori(i, n) for(int i=1; i<=n; i++)
# define Each(x, v) for(auto x : v)
int n, m, a[25], b[25], memo[25][(1<<20)+5];
vector<int> bitmasks[20005];
int dp(int i, int mask){
if(i==n) return 1;
int &res = memo[i][mask];
if(res != -1) return res;
res = 0;
for(int bit : bitmasks[a[i]]){
if((bit & mask) != 0) continue;
res = max(res, dp(i+1, mask | bit));
}
return res;
}
signed main(){
ios_base :: sync_with_stdio(false);
memset(memo, -1, sizeof(memo));
cin >> n >> m;
for(int i=0; i<n; i++) cin >> a[i];
for(int i=0; i<m; i++) cin >> b[i];
for(int mask=0; mask<(1<<m); mask++){
int sum = 0;
for(int i=0; i<m; i++)
if((mask >> i)&1) sum += b[i];
bitmasks[sum].push_back(mask);
}
if(dp(0,0) == 1) cout << "YES" << endl;
else cout << "NO" << endl;
}
# | 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... |