이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define N 20
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i, l, r) for(int i = l; i <= r; i++)
#define rep2(i, l, r) for(int i = r; i >= l; i--)
using namespace std;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef pair<ii, ii> iv;
typedef unsigned long long ull;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const bool multi_test = false;
const string NAME = "bt";
int exp(int x, int y){
int res = 1;
while (y){
if (y & 1) res = res * x % MOD;
x = x * x % MOD;
y >>= 1;
}
return res;
}
int n, m;
int a[N+5], b[N+5];
bool dp[N+5][(1<<N)+5];
int sum_mask[(1<<N)+5];
void solve(){
cin >> n >> m;
rep(i, 1, n) cin >> a[i];
rep(i, 1, m) cin >> b[i];
rep(mask, 1, (1<<m) - 1){
rep(i, 1, m){
if ((mask >> (i-1)) & 1) sum_mask[mask] += b[i];
}
}
dp[0][0] = 1;
rep(i, 1, n){
rep(mask, 0, (1<<m) - 1){
for(int mask2 = mask; mask2; mask2 = (mask2 - 1) & mask){
int k = mask ^ mask2;
if (dp[i-1][mask2] && sum_mask[k] == a[i]){
dp[i][mask] = 1;
}
}
if (sum_mask[mask] == a[i] && dp[i-1][0]) dp[i][mask] = 1;
// cout << i << " " << mask << " " << dp[i][mask] << endl;
}
}
bool ac = false;
rep(mask, 1, (1<<m) - 1){
if (dp[n][mask]) ac = true;
}
if (ac) cout << "YES";
else cout << "NO";
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
if (multi_test) cin >> t;
while (t--) solve();
}
# | 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... |