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 pii = pair<int,int>;
const int maxn = 20,inf = 1e9;
int n,m,dp[maxn][1 << maxn];
vector<int> s,c;
bool solve(int pos,int mask){
if(pos == n) return 1;
if(dp[pos][mask] != -1) return dp[pos][mask];
dp[pos][mask] = 0;
for(int i = 1;i < (1 << m);i++){
int soma = 0;
for(int j = 0;j < m;j++)
if(i & (1 << j) && !(mask & (1 << j)))
soma += c[j];
if(soma == s[pos]) dp[pos][mask] |= solve(pos + 1,mask | i);
}
return dp[pos][mask];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n >> m;
s.resize(n);
c.resize(m);
for(int &i : s) cin >> i;
for(int &i : c) cin >> i;
memset(dp,-1,sizeof dp);
cout << (solve(0,0) ? "YES" : "NO");
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... |