# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1090866 | vjudge1 | Bank (IZhO14_bank) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using tii = tuple<int,int,int>;
const int maxn = 2e1 + 5;
int n,m,s[maxn],c[maxn],dp[maxn][1 << maxn];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for(int i = 0;i < n;i++) cin >> s[i];
for(int i = 0;i < m;i++) cin >> c[i];
for(int i = 0;i < n;i++)
for(int j = 0;j < (1 << n);j++)
dp[0][0] = -1;
dp[0][0] = 0;
for(int i = 0;i < n;i++)
for(int mask = 0;mask < (1 << m);mask++)
if(dp[i][mask] != -1){
if(dp[i][mask] == s[i]){
if(i == n - 1){
cout << "YES";
return 0;
}
else dp[i + 1][mask] = 0;
}
for(int j = 0;j < m;j++)
if(!(mask & (1 << j))) dp[i][mask | (1 << j)] = dp[i][mask] + c[j];
}
cout << "NO";
return 0;
}