이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <cmath>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
typedef long long ll;
ll linf = 1e15+1;
inline void scoobydoobydoo(){
ios::sync_with_stdio(false);
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
vector<int> ways[21];
int mem[21][1048577];
int n, m;
int dp(int index, int used){
if (index == n)return 0;
if (mem[index][used] != -1)return mem[index][used];
int best = 0;
for (int x : ways[index]){
if ((x | used) == (x ^ used))best = max(best, dp(index+1, used | x)+1);
}
return mem[index][used] = best;
}
int main(){
scoobydoobydoo();
cin >> n >> m;
vector<int> salaries(n);
vector<int> notes(m);
for (int i = 0; i < n; i++)cin >> salaries[i];
for (int i = 0; i < m; i++)cin >> notes[i];
for (int j = 0; j < (1<<m); j++){
int sum = 0;
for (int x = 0; x < m; x++){
if ((1<<x)&j)sum += notes[x];
}
for (int i = 0; i < n; i++){
if (salaries[i] == sum)ways[i].push_back(j);
mem[i][j] = -1;
}
}
if (dp(0, 0) == n)cout << "YES" << endl;
else cout << "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... |