제출 #595920

#제출 시각아이디문제언어결과실행 시간메모리
595920Belphegor은행 (IZhO14_bank)C++14
100 / 100
600 ms22988 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; int n,m; vector<int>graph[22]; int A[22],B[22]; char dp[22][(1<<20)]; char f(int cur,int state){ char&ret = dp[cur][state]; if(~ret) return ret; ret = 0; if(cur==n) return ret = 1; for(int s : graph[cur]){ if((state&s)==s) ret|=f(cur+1,state^s); } return ret; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); 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=1; i<(1<<m); i++){ int tot = 0; for(int j=0; j<m; j++) if(i&(1<<j)) tot+=B[j]; for(int j=0; j<n; j++) if(A[j]==tot) graph[j].emplace_back(i); } memset(dp,-1,sizeof(dp)); cout<<(f(0,(1<<m)-1)?"YES":"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...