제출 #441932

#제출 시각아이디문제언어결과실행 시간메모리
441932tht2005은행 (IZhO14_bank)C++17
100 / 100
343 ms205580 KiB
#include <bits/stdc++.h> using namespace std; #define nmax 25 int n, m, a[nmax], b[nmax], f[nmax][1<<21]; int dp(int i, int mask, int64_t sum) { if(f[i][mask] != -1) return f[i][mask]; if(i >= n) return f[i][mask] = 1; f[i][mask] = 0; for(int t = 0; t < m; ++t) { if((mask >> t) & 1) continue; if(sum + b[t] < a[i]) { if(dp(i, mask | (1 << t), sum + b[t])) f[i][mask] = 1; } else if(sum + b[t] == a[i]) { if(dp(i + 1, mask | (1 << t), 0)) f[i][mask] = 1; } } return f[i][mask]; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for(int i = 0; i < n; ++i) cin >> a[i]; for(int i = 0; i < m; ++i) cin >> b[i]; memset(f, -1, sizeof(f)); cout << (dp(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...