This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int>PI;
typedef pair<ll, ll > PL;
typedef vector<int>VI;
typedef vector<ll>VL;
#define FF first
#define SS second
const int mod = 1e9 + 7;
const int INF = 1e9;
const int N = 20;
ll dp[22][(1 << N) + 5];
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//freopen("bank.in", "r", stdin);
//freopen("bank.out", "w", stdout);
int n, m;
cin >> n >> m;
int a[n], b[m];
for (int i = 0; i < n; i++)cin >> a[i];
for (int i = 0; i < m; i++)
{
cin >> b[i];
}
for (int i = 0; i <= 21; i++)
for (int j = 0; j <= (1 << N); j++) dp[i][j] = -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) continue;
for (int k = 0; k < m; k++)
if (((mask >> k) & 1) == 0)
dp[i][mask | (1 << k)] = dp[i][mask] + b[k];
}
for (int mask = 0; mask < (1 << m); mask++)
{
if (dp[i][mask] == a[i]) dp[i + 1][mask] = 0;
}
}
bool f1 = 0;
for (int mask = 0; mask < (1 << m); mask++)
if (dp[n][mask] == 0) f1 = 1;
if (f1)
cout << "YES" << endl;
else cout << "NO" << endl;
cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |