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;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
typedef pair<pair<ll, ll>, pair<ll, ll>> lll;
typedef pair<int, ii> iii;
#define pb push_back
#define ms memset
#define fi first
#define se second
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = a; i >= b; i--)
ll MOD = 1000000007;
ll power(ll base, int n){
if (n == 0) return 1;
if (n == 1) return base;
ll halfn = power(base, n/2);
if (n % 2 == 0) return (halfn * halfn) % MOD;
return (((halfn * halfn) % MOD) * base) % MOD;
}
ll inverse(int n){
return power(n, MOD-2);
}
ll gcd(ll a, ll b){
if (a == 0) return b;
if (a == 1) return 1;
return gcd(b % a, a);
}
ll lcm(ll a, ll b){
return (a * b) / gcd(a, b);
}
const int N = 100001;
int n, m;
vi a(20), b(20);
bool sol = false;
void DP(int mask, int pos){
if (pos == n){
sol = true; return;
}
FOR(i, 0, (1<<m)){
if ((mask^i) == mask-i){
int val = 0;
FOR(j, 0, m){
if (i & (1<<j)){
val += b[j];
}
}
if (val == a[pos]){
DP(mask^i, pos+1);
}
}
}
}
void solve(){
cin >> n >> m;
FOR(i, 0, n) cin >> a[i];
FOR(i, 0, m) cin >> b[i];
DP((1<<m)-1, 0);
if (sol) cout << "YES\n";
else cout << "NO\n";
return ;
}
int main(){
ios::sync_with_stdio(false);
int TC = 1;
//cin >> TC;
FOR(i, 1, TC+1){
//cout << "Case #" << i << ": ";
solve();
}
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... |