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;
int a[21];
int b[20];
int sum[1 << 20];
int n,m;
bool dp[1 << 20][21];
int getbit(int x, int i)
{
return (x >> i) & 1;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("bank.in","r",stdin);
//freopen("bank.out","w",stdout);
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> a[i], a[i] += a[i - 1];
for (int i = 0; i < m; i++)
cin >> b[i];
for (int mask = 0; mask < (1 << m); mask++)
for (int i = 0; i < m; i++)
if (getbit(mask, i))
sum[mask] += b[i];
dp[0][0] = true;
for (int mask = 0; mask < (1 << m); mask++)
for (int i = 0; i <= n; i++) if (dp[mask][i])
{
if (sum[mask] == a[i])
{
if (i == n)
return cout << "YES\n", 0;
dp[mask][i + 1] = true;
} else {
for (int j = 0; j < m; j++)
if (!getbit(mask, j))
dp[mask | (1 << j)][i] = true;
}
}
cout << "NO\n";
return 0;
}
# | 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... |