제출 #917820

#제출 시각아이디문제언어결과실행 시간메모리
917820KactusJack은행 (IZhO14_bank)C++17
100 / 100
360 ms90820 KiB
#include<bits/stdc++.h> #define ll long long #define F first #define S second using namespace std; int n, m; vector<int> a, b, sum, prefix; vector<vector<int>> mem; int dp(int i, int mask){ if(i == n){ return 1; } int &ret = mem[i][mask]; if(ret != -1){ return ret; } ret = 0; int rest = prefix[i] - sum[mask]; if(rest == 0){ ret = dp(i+1, mask); } else{ for(int j = 0; j < m; j++){ if(!(mask&(1<<j)) && b[j] <= rest){ ret = max(ret, dp(i, mask^(1<<j))); } } } return ret; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); //freopen("bank.in", "r", stdin); //freopen("bank.out", "w", stdout); cin >> n >> m; a = vector<int> (n); for(int i = 0; i < n; i++){ cin >> a[i]; } b = vector<int> (m); for(int i = 0; i < m; i++){ cin >> b[i]; } prefix = vector<int> (n); prefix[0] = a[0]; for(int i = 1; i < n; i++){ prefix[i] = prefix[i-1] + a[i]; } sum = vector<int> (1<<m); for(int mask = 0; mask < (1<<m); mask++){ for(int i = 0; i < m; i++){ if((mask&(1<<i))){ sum[mask] += b[i]; } } } mem = vector<vector<int>> (n, vector<int> (1<<m, -1)); cout << (dp(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...