제출 #430827

#제출 시각아이디문제언어결과실행 시간메모리
430827jli12345은행 (IZhO14_bank)C++14
0 / 100
6 ms716 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...