//UPDATERA ARRAY STORLEKEN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e15;
const ll MAXN=21;//UPDATERA ARRAY STORLEKEN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ll n,dp[1<<MAXN][MAXN],ans,salary[MAXN],notes[MAXN],m;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>salary[i];
for(int i=1;i<=m;i++) cin>>notes[i];
for(int i=1;i<(1<<m);i++) dp[i][0]=1;
//transition from subset to set
for(int k=1;k<=n;k++){
for(int s=1;s<(1<<m);s++){
for(int i=s;i;i=(i-1)&s){//i not empty set
ll tot=0;
for(int j=1;j<=m;j++){
if(i&(1<<(j-1))){
tot+=notes[j];
}
}
if(tot==salary[k]){
dp[s][k]|=dp[s^i][k-1];
}
dp[s][k]|=dp[s^i][k];
}
}
}
if(dp[(1<<m)-1][n]) cout<<"YES"<<'\n';
else cout<<"NO"<<'\n';
}
| # | 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... |