제출 #922587

#제출 시각아이디문제언어결과실행 시간메모리
922587THXuan은행 (IZhO14_bank)C++14
71 / 100
934 ms3152 KiB
// dp[i][mask] = true if the first i-th person is considered and the on bit in mask is taken // base case dp[0][0] = true; #include <iostream> #include <vector> #include <algorithm> #include <queue> #include <set> #include <map> #define INF 1e9 using namespace std; typedef long long ll; bool dp[30][300000]; vector<int>val[30]; void solve() { int n, m; cin >> n >> m; vector<int>a(n + 1), b(m + 1); for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= m; i++) cin >> b[i]; for (int mask = 0; mask < (1 << m); mask++) { int sum = 0; for (int i = 0; i < m; i++) { if (mask & (1 << i))sum += b[i + 1]; } for (int i = 1; i <= n; i++) { if (a[i] == sum) val[i].push_back(mask); } } dp[0][0] = true; for (int i = 0; i < n; i++) { for (int mask = 0; mask < (1 << m); mask++) { if (!dp[i][mask]) continue; for (auto u : val[i + 1]) { if ((mask & u) == 0) dp[i + 1][mask | u] |= dp[i][mask]; } } } for (int mask = 0; mask < (1 << m); mask++) { if (dp[n][mask]) { cout << "YES" << "\n"; return; } } cout << "NO" << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1;// cin>>t; while (t--) solve(); 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...