#include<bits/stdc++.h>
using namespace std;
int n,m,a[25],B[25],dp[2000006][25],i,j,k,s;
vector<int>V[25];
bool go(int b,int i){
if(i==n) {
return 1;
}
bool F=0;
//cout<<i<<endl;
if(dp[b][i]!=-1) return dp[b][i];
for(int j=0;j<V[i].size();j++){
if((b&V[i][j])==V[i][j]) {
F=max(F,go(b^V[i][j],i+1));
}
}
if (!F) {
dp[b][i]=0; return 0;
}
return 1;
}
int main(){
cin>>n>>m;
for(k=0;k<n;k++){
cin>>a[k];
}
for(k=0;k<m;k++)
cin>>B[k];
for(k=0;k<n;k++){
s=0;
for(i=0;i< (1<<m); i++){
s=0; dp[i][k]=-1;
for(int j=0;j<=m;j++){
int b=1<<j;
if(b&i)s+=B[j];
}
if(s==a[k]) V[k].push_back(i);
}
}int b=1<<(m);
if(go(b-1,0))cout<<"YES";
else cout<<"No";
}
Compilation message
bank.cpp: In function 'bool go(int, int)':
bank.cpp:12:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | for(int j=0;j<V[i].size();j++){
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1920 KB |
Output is correct |
2 |
Correct |
4 ms |
1860 KB |
Output is correct |
3 |
Correct |
11 ms |
1920 KB |
Output is correct |
4 |
Incorrect |
16 ms |
1920 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |