제출 #392370

#제출 시각아이디문제언어결과실행 시간메모리
392370SirCovidThe19th은행 (IZhO14_bank)C++14
100 / 100
136 ms8492 KiB
#include <bits/stdc++.h> using namespace std; int main(){ //n people, m banknotes int n, m; cin >> n >> m; int salary[n]; int banknote[m]; int store = 0; for (int i = 0; i < n; i++){ cin >> salary[i]; salary[i] += store; store = salary[i]; } for (int i = 0; i < m; i++) cin >> banknote[i]; int dp[1<<m]; int sum[1<<m]; memset(dp, 0, sizeof(dp)); memset(sum, 0, sizeof(sum)); for (int i = 0; i < (1<<m); i++){ if (dp[i] == n){ cout<<"YES"<<endl; return 0; } for (int j = 0; j < m; j++){ if ((i&(1<<j)) != 0) continue; sum[i^(1<<j)] = sum[i]+banknote[j]; if (salary[dp[i]] == sum[i]+banknote[j]) dp[i^(1<<j)] = max(dp[i^(1<<j)], dp[i]+1); else dp[i^(1<<j)] = max(dp[i^(1<<j)], dp[i]); } } cout<<"NO"<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...