제출 #173493

#제출 시각아이디문제언어결과실행 시간메모리
173493itgl은행 (IZhO14_bank)C++14
100 / 100
281 ms18840 KiB
#include<bits/stdc++.h> using namespace std; int n,m; int a[21],b[21]; bool dp[21][1<<21]; bool vis[21][1<<21]; vector<int> lis[21]; int sum[1<<21]; bool solve(int p, int mask){ if(p==n) return 1; if(vis[p][mask]) return dp[p][mask]; vis[p][mask]=1; int s=lis[p].size(); for(int i=0;i<s;i++){ int x=lis[p][i]; if(!(x&mask)&&solve(p+1,mask|x)) return 1; } return 0; } int main(){ cin >> n >> m; for(int i=0;i<n;i++)cin >> a[i]; for(int i=0;i<m;i++)cin >> b[i]; for(int i=0;i<(1<<m);i++){ for(int j=0;j<m;j++){ if(i&(1<<j))sum[i]+=b[j]; } } for(int i=0;i<n;i++){ for(int j=0;j<(1<<m);j++){ if(sum[j]==a[i])lis[i].push_back(j); } } if(solve(0,0)){ cout << "YES\n"; }else cout << "NO\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...