제출 #404137

#제출 시각아이디문제언어결과실행 시간메모리
404137fadi57은행 (IZhO14_bank)C++14
100 / 100
680 ms94380 KiB
#include<bits/stdc++.h> using namespace std; const int mx=30; typedef long long ll; int inf=1e9+10; const int mod=1e9+7; int a[30]; int b[30]; int x[mx]; int n,m; vector<int>sums[20005]; map<int,int>mp; int dp[21][(1<<20)+2]; int solve(int i,int mask){ if(i==n){ return 1; } int &ret=dp[i][mask]; if(ret!=-1){ return ret; } ret=0; for(auto it:sums[a[i]]){ if((it&mask)==it){ ret=max(solve(i+1,mask^it),ret); } } return ret; } 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++){ int sum=0; for(int j=0;j<m;j++){ if(i&(1<<j)){ sum+=b[j]; } } sums[sum].push_back(i); } memset(dp,-1,sizeof(dp)); // cout<<sums[3][0]; if(solve(0,(1<<m)-1)){ cout<<"YES"; }else{ cout<<"NO"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...