제출 #710378

#제출 시각아이디문제언어결과실행 시간메모리
710378JJAnawat은행 (IZhO14_bank)C++14
100 / 100
107 ms8520 KiB
#include<bits/stdc++.h> #define F first #define S second using namespace std; int n,m; int a[25],b[25]; pair<int,int> dp[1<<20]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for(int i=1;i<=n;i++) cin >> a[i]; for(int i=0;i<m;i++) cin >> b[i]; for(int i=0;i<(1<<m);i++) dp[i]={-1,-1}; dp[0]={0,0}; for(int st=1;st<(1<<m);st++){ for(int j=0;j<m;j++){ if(st&(1<<j)){ int prv=st^(1<<j); if(dp[prv].F==-1) continue; //cout << st << " "; int total=dp[prv].S+b[j]; if(total==a[dp[prv].F+1]){ if(dp[prv].F+1>dp[st].F){ dp[st]={dp[prv].F+1,0}; } } else{ if(dp[prv].F>dp[st].F){ dp[st]={dp[prv].F,total}; } } } } if(dp[st].F==n){ cout << "YES"; return 0; } //cout << dp[st].F << ' '; } 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...