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 <iostream>
using namespace std;
int a[25];
int b[25];
bool o[25][(1<<20)+1];
void dfs(int n, int m, int ix, int ob)
{
// cout << ix << " " << ob << " " << a[ix] << "\n";
if (ix == n)
{
cout << "YES\n";
exit(0);
}
if (ob == ((1<<m)-1))
return;
if (a[ix] < 0)
return;
if (o[ix][ob])
return;
if (a[ix] == 0)
dfs(n, m, ix+1, ob);
for (int i = 0; i < m; i++)
if (((1<<i)&ob) == 0)
{
a[ix]-=b[i];
dfs(n, m, ix, ob|(1<<i));
a[ix]+=b[i];
}
o[ix][ob] = 1;
}
int main()
{
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < m; i++)
cin >> b[i];
dfs(n, m, 0, 0);
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... |