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 n, m;
vector<int> opt;
vector<int> money;
void determine(int depth, int cash, int state)
{
if (depth<0)
{
if (cash == 0) opt.push_back(state);
return;
}
determine(depth-1, cash, state);
determine(depth-1, cash-money[depth], state+(1<<depth));
}
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int n, m;
cin >> n >> m;
vector<int> comb(1<<m, 0);
comb[(1<<m) -1]=1;
money.assign(m, 0);
vector<int> people(n);
for (int i = 0; i < n; i++) cin >> people[i];
for (int i = 0; i < m; i++) cin >> money[i];
bool b = 1;
for (int ele:people)
{
opt.clear();
vector<int> comb2(1<<m, 0);
determine(m-1, ele, 0);
for (int i = 0; i < (1<<m); i++)
{
if (!comb[i]) continue;
for (int ele:opt)
{
if ((ele & i) == ele) comb2[i-ele] = 1;
}
}
b=0;
for (int i = 0; i < (1<<m); i++)
{
comb[i] = comb2[i];
if (comb2[i]) b=1;
}
}
if (b) cout << "YES";
else cout << "NO";
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... |