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 v[22],a[22];
vector <int> L[22];
int n,m,i,sol;
void back (int pas, int mask){
if (sol)
return;
if (pas > n){
sol = 1;
return;
}
for (auto it : L[pas]){
if ( (it & mask) == 0)
back (pas+1,mask | it);
}
}
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>n>>m;
for (i=1;i<=n;i++)
cin>>v[i];
for (i=0;i<m;i++)
cin>>a[i];
for (i=1;i<=n;i++){
for (int mask=0;mask<(1<<m);mask++){
int sum = 0;
for (int bit=0;bit<m;bit++){
if (mask & (1<<bit))
sum += a[bit];
}
if (sum == v[i])
L[i].push_back(mask);
}
}
back (1,0);
if (sol)
cout<<"YES";
else 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... |