제출 #928027

#제출 시각아이디문제언어결과실행 시간메모리
928027mariamp1은행 (IZhO14_bank)C++14
100 / 100
151 ms4684 KiB
#include <iostream> #include <algorithm> #include <vector> #include <map> using namespace std; const int mod = 1e9 + 7; int dp[(1<<21)]; int main(){ int n, m; cin >> n >> m; int mas[n]; int pref[n]; for(int i = 0; i < n; i++){ cin >> mas[i]; } pref[0] = mas[0]; for(int i = 1; i < n; i++){ pref[i] = pref[i-1] + mas[i]; } int kup[m]; for(int i = 0; i < m; i++){ cin >> kup[i]; } for(int i = 0; i < (1 << m); i++){ int sum = 0; for(int j = 0; j < m; j++){ if((1 << j) & i) { sum += kup[j]; } } for(int j = 0; j < m; j++){ if((1 << j) & i) { if(sum == pref[dp[i - (1 << j)]]) dp[i] = max(dp[i], dp[i - (1 << j)] + 1); else dp[i] = max(dp[i], dp[i - (1 << j)]); } } } if(dp[(1 << m) - 1] == n) cout << "YES" << endl; else 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...