This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Suleyman Atayew
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#define N 10010
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define inf 1000000007
#define pii pair <ll, ll>
using namespace std;
ll sum;
ll n, m;
ll v[N];
ll arr[N];
int dp[30][(1<<21)];
vector <int> E[30];
void bit(int x, int y)
{
if(x == n) {
cout << "YES";
exit(0);
}
if(dp[x][y]) return;
dp[x][y] = 1;
for(auto i: E[x+1])
if((i&y) == 0) bit(x+1, (i | y));
}
int main()
{
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> v[i];
for(int i = 0; i < m; i++) cin >> arr[i];
for(int h = 0; h < (1<<m); h++) {
int sum = 0;
for(int j = 0; j < m; j++)
if((h&(1<<j))) sum += arr[j];
for(int i = 1; i <= n; i++)
if(sum == v[i]) E[i].pb(h);
}
bit(0, 0);
cout << "NO";
}
# | 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... |