제출 #880958

#제출 시각아이디문제언어결과실행 시간메모리
880958Younis_Dwai은행 (IZhO14_bank)C++14
100 / 100
238 ms259152 KiB
#include <bits/stdc++.h> //#define int long long #define in insert #define F first #define S second #define pb push_back //#define endl "\n" //#define mid (l+r)/2 #define all(v) v.begin(),v.end() //#define pop pop_back using namespace std; using std::cout; using std::endl; const int M=1e9+7; int n,m; int a[25],b[25]; int dp[21][3000009]; vector<int> adj[200009]; int rec(int id , int mask){ if(dp[id][mask]!=-1) return dp[id][mask]; else if(id==n) return 1; int c=0; for(auto u : adj[a[id]]){ if((mask&u)) continue ; c=max(c,rec(id+1,(mask|u))); if(c==1) break; } return dp[id][mask]=c; } int main(){ memset(dp,-1,sizeof dp); std::cin>>n>>m; for(int i=0;i<n;i++) std::cin>>a[i]; for(int i=0;i<m;i++) std::cin>>b[i]; for(int mask=1;mask<(1<<m);mask++){ int sum=0; for(int i=0;i<m;i++){ if((mask&(1<<i))) sum+=b[i]; } adj[sum].pb(mask); } if(rec(0,0)==1) cout<<"YES"<<endl; else cout<<"NO"<<endl; 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...