제출 #438798

#제출 시각아이디문제언어결과실행 시간메모리
438798jalsol은행 (IZhO14_bank)C++17
100 / 100
154 ms4352 KiB
#ifdef LOCAL #include <local.h> #else #include <bits/stdc++.h> #define debug(...) #endif const int maxn = 20; int n, m; int a[maxn]; int b[maxn]; int dp[1 << maxn]; int go(int i, int mask, int sum) { if (i >= n) return true; int &ret = dp[mask]; if (ret != -1) return ret; for (int j = 0; j < m; j++) { if (mask >> j & 1) continue; if (sum + b[j] == a[i]) { if (go(i + 1, mask | (1 << j), 0)) { return ret = true; } } else if (sum + b[j] < a[i]) { if (go(i, mask | (1 << j), sum + b[j])) { return ret = true; } } } return ret = false; } signed main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); 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]; } std::fill_n(dp, 1 << maxn, -1); std::cout << (go(0, 0, 0) ? "YES" : "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...