이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define mod 1000000007
#define sp << " " <<
#define endl << '\n'
long long int N, M;
vector<int> people;
vector<int> banknotes;
vector<vector<int>> memoization;
int dp(int n, long long int mask);
inline int calldp(int n, long long int mask, int need, int opt = M - 1){
if (need == 0)
return dp(n, mask);
for (int i = opt; i >= 0 && banknotes[i] >= need / 2; i--){
if (mask & (1 << i))
continue;
if (calldp(n, mask | (1 << i), need - banknotes[i], i - 1))
return 1;
}
return 0;
}
int dp(int n, long long int mask){
if (n == N)
return 1;
if (memoization[n][mask] != -1)
return memoization[n][mask];
memoization[n][mask] = calldp(n + 1, mask, people[n]);
return memoization[n][mask];
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N >> M;
people.resize(N);
banknotes.resize(M);
memoization.resize(N, vector<int>(1 << M, -1));
for (int i = 0; i < N; i++)
cin >> people[i];
for (int o = 0; o < M; o++)
cin >> banknotes[o];
sort(all(banknotes));
if (dp(0, 0)){
cout << "YES";
}else
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... |