제출 #914415

#제출 시각아이디문제언어결과실행 시간메모리
914415thisistotallymyusername은행 (IZhO14_bank)C++14
71 / 100
1051 ms178556 KiB
#include <bits/stdc++.h> using namespace std; const int N = 21, M = 1 << N, K = 1010; int dp[N][M]; int n, m, mx, a[N], b[N]; vector<int> s[K]; bool check(int i, int msk) { for (int j = 0; j < N; j++) { if (i >> j & 1 && !(msk >> j & 1)) { return false; } } return true; } int g(int i, int msk) { for (int j = 0; j < N; j++) { if (i >> j & 1) { msk = msk & ~(1 << j); } } return msk; } bool f(int u, int msk) { if (dp[u][msk] == 1 || u == 0) { return true; } if (dp[u][msk] == 0) { return false; } for (int i : s[a[u]]) { if (check(i, msk) && f(u - 1, g(i, msk))) { dp[u][msk] = 1; return true; } } dp[u][msk] = 0; return false; } int main() { memset(dp, -1, sizeof dp); cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; mx = max(mx, a[i]); } for (int j = 1; j <= m; j++) { cin >> b[j]; } for (int i = 0; i < 1 << m; i++) { int sum = 0; for (int j = 0; j < N; j++) { if (i >> j & 1) { sum += b[j + 1]; } } if (sum > mx) continue; s[sum].push_back(i); } cout << (f(n, (1 << m) - 1) ? "YES\n" : "NO\n"); 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...