이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << x << '\n';
template<typename T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<typename T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
constexpr int MOD = 1e9 + 7;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LLINF = 0x3f3f3f3f3f3f3f3f;
#define int long long
bool dp[(1 << 20) + 3][22];
vector<int> consists[20];
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m; cin >> n >> m;
vector<int> people(n), notes(m);
for (auto& a : people) cin >> a;
for (auto& a : notes) cin >> a;
memset(dp, 0, sizeof(dp));
for (int i = 0; i < (1 << m); i++) {
int thing = 0;
for (int j = 0; j < m; j++) {
if (i & (1 << j)) thing += notes[j];
}
for (int j = 0; j < n; j++) {
if (thing == people[j]) consists[j].push_back(i);
}
}
dp[0][0] = true;
for (int i = 0; i < n; i++) {
for (int mask = 0; mask < (1 << m); mask++) {
if (!dp[mask][i]) continue;
for (auto thing : consists[i]) {
if (!(thing & mask)) { //no intersection
dp[thing | mask][i + 1] = true;
}
}
}
}
bool works = false;
for (int i = 0; i < (1 << m); i++) {
if (dp[i][n]) works = true;
}
cout << ((works) ? "YES" : "NO") << endl;
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... |