Submission #1132880

#TimeUsernameProblemLanguageResultExecution timeMemory
1132880DangKhoizzzzBank (IZhO14_bank)C++20
0 / 100
1094 ms460 KiB
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define pii pair <int , int> #define ar3 array <int , 3> using namespace std; const int INF = 1e9 + 7; const int maxn = 2e5 + 7; int n , m , a[40] , b[40]; bool dp[40][10000]; bool check(int a , int b) { for(int i = 0; i <= 20; i++) { if(!((a >> i)&1) && (b >> i)&1) return 0; } return 1; } void solve() { cin >> n >> m; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= m; i++) cin >> b[i]; dp[0][0] = 1; for(int i = 1; i <= n; i++) { for(int mask1 = 1; mask1 < (1 << m); mask1++) { for(int mask2 = 1; mask2 < (1 << m); mask2++) { if(!check(mask1 , mask2)) continue; int sum = 0; for(int j = 0; j < m; j++) { if((mask2 >> j)&1) sum += b[j+1]; } if(sum == a[i]) { dp[i][mask1] = max(dp[i-1][(mask1^mask2)] , dp[i-1][mask1]); } } } } bool ans = 0; for(int mask = 0; mask < (1 << m); mask++) { ans = max(ans , dp[n][mask]); } if(ans) cout << "YES" << '\n'; else cout << "NO" << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); 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...