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 ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;
int n, m;
const int maxn = 1000;
int a[21], b[21];
vector<int>tmp[21];
int main()
{
// freopen("BANK.INP", "r", stdin);
// freopen("BANK.OUT", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int j = 0; j < m; j++) cin >> b[j];
vector<vector<bool>>dp(21, vector<bool>((1 << 20), false));
dp[0][0] = true;
for(int i = 1; i <= n; i++)
{
for(int mask = 1; mask < (1 << m); mask++)
{
int res = 0;
for(int j = 0; j < m; j++)
{
if(mask & (1 << j))
res += b[j];
}
if(res == a[i])
{
tmp[i].pb(mask);
}
}
}
for(int i = 1; i <= n; i++)
{
//cout << "test: " << i << '\n';
for(int j : tmp[i])
{
// cout << j << ' ';
for(int mask = 0; mask < (1 << m); mask++)
{
if(!(j & mask) && dp[i - 1][mask]) {
dp[i][j|mask] = 1;
if(i == n) {
cout << "YES";
return 0;
}
}
}
}
// cout << '\n';
}
cout << "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... |