제출 #882802

#제출 시각아이디문제언어결과실행 시간메모리
882802skywwla은행 (IZhO14_bank)C++17
100 / 100
223 ms86704 KiB
#include <bits/stdc++.h> using namespace std ; using ll = long long ; int32_t main() { ios::sync_with_stdio(false) ; cin.tie(nullptr) ; int n , m ; cin >> n >> m ; vector<ll> a(n), b(m) ; for (ll &i : a) cin >> i ; for (ll &i : b) cin >> i ; vector<vector<int>> dp(n, vector<int>(1 << m, -1)) ; function<bool(int,int)> solve = [&](int i, int mask) { if (i == n) return true ; if (~dp[i][mask]) return bool(dp[i][mask]) ; bool ret = false ; for (int j = 0 ; j < m ; j++) { if ((mask >> j & 1)) continue ; if (a[i] >= b[j]) { a[i] -= b[j] ; int nxti = i + (!a[i]) ; ret |= solve(nxti, mask | (1 << j)) ; a[i] += b[j] ; } } dp[i][mask] = ret ; return ret ; }; cout << (solve(0, 0) ? "YES" : "NO") ; 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...