#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;
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]) {
if(i+1==n) return 1;
else if(dp[b^V[i][j]][i+1]!=-1)F=max(F,go(b^V[i][j],i+1));
}
}
if (!F) {
dp[b][i]=0; return 0;
}
return dp[b][i]=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:11:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | for(int j=0;j<V[i].size();j++){
| ~^~~~~~~~~~~~
bank.cpp:20:17: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
20 | return dp[b][i]=1;
| ~~~~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
3584 KB |
Output is correct |
5 |
Correct |
118 ms |
102904 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
121 ms |
103032 KB |
Output is correct |
9 |
Correct |
125 ms |
102864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
1920 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
3584 KB |
Output is correct |
5 |
Correct |
118 ms |
102904 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
121 ms |
103032 KB |
Output is correct |
9 |
Correct |
125 ms |
102864 KB |
Output is correct |
10 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |