이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<complex>
using namespace std;
typedef long long ll;
typedef complex<double> pt;
#define x() real()
#define y() imag()
#define smx(a, b) a = max(a, b)
#define smn(a, b) a = min(a, b)
#define in(mp, v) mp.find(v) != mp.end()
const int MAXN = 20;
const int MOD = 1000000007;
int n, m, a[MAXN+1], b[MAXN];
bool work[MAXN+1][1<<MAXN];
vector<int> combs[MAXN+1];
int sum(int x) {
int ret = 0, i = 0;
for (; x; i++, x>>=1) ret += b[i]*(x&1);
return ret;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int j = 0; j < m; j++) cin >> b[j];
for (int k = 0; k < (1<<m); k++) {
int sm = sum(k);
for (int i = 1; i <= n; i++) {
if (sm == a[i]) {
combs[i].push_back(k);
}
}
}
work[0][0] = true;
bool found;
for (int i = 1; i <= n; i++) {
found = false;
for (int k = 0; k < (1<<m); k++) {
if (work[i-1][k]) {
for (int c : combs[i]) {
if ((k & c) == 0) {
work[i][k|c] = true;
found = true;
}
}
}
}
if (!found) break;
}
if (found) {
cout << "YES" << endl;
} else cout << "NO" << endl;
}
# | 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... |