이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
//#define int ll
const int N = 20;
const int INF = 1e9;
int n, m, a[N], b[N];
vector <int> mask[N];
bool visited[N][(1 << N)];
void rec(int i, int state) {
if(i == n) {
cout << "YES";
exit(0);
}
if(visited[i][state]) return;
visited[i][state] = true;
for(int s : mask[i]) {
if(state & s) continue;
rec(i + 1, (state | s));
}
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for(int i = 0; i < n; ++i) {
cin >> a[i];
}
for(int i = 0; i < m; ++i) {
cin >> b[i];
}
for(int state = 0; state < (1 << m); ++state) {
int sum = 0;
for(int i = 0; i < m; ++i) if (state & (1 << i)) sum += b[i];
for(int i = 0; i < n; ++i) if (a[i] == sum) mask[i].pb(state);
}
rec(0, 0);
cout << "NO";
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... |