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;
void fastIO(){
ios_base::sync_with_stdio(false);
cin.tie(0);
}
int N, M;
int b[21], a[21];
int dp[21][(1<<20)];
int main(){
//fastIO();
cin >> N >> M;
for (int i = 1; i <= N; i++)
cin >> b[i];
for (int i = 1; i <= M; i++){
cin >> a[i];
}
dp[0][0] = 1;
b[0] = 1;
for (int i = 1; i <= N; i++){
for (int j = 1; j < (1<<M); j++){
for (int k = 1; k <= M; k++){
if (j&(1<<(k-1))){
if (dp[i][j] == 0 && dp[i-1][j^(1<<(k-1))] == b[i-1]){
dp[i][j] = a[i];
} else if (dp[i-1][j^(1<<(k-1))] != 0){
dp[i][j] += dp[i-1][j^(1<<(k-1))]+a[i];
}
}
}
}
}
bool work = false;
for (int j = 1; j < (1<<M); j++){
if (dp[N][j] == a[N]){
work = true;
break;
}
}
if (work)
cout << "YES\n";
else
cout << "NO\n";
}
# | 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... |