이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool posible(int indiceEmpleado, int mascara, vector<int> & salarios, vector<vector<int>> & formasDeLlegar, vector<vector<int>> & DP) {
if (indiceEmpleado == (int) salarios.size())
return true;
if (DP[indiceEmpleado][mascara] != -1)
return DP[indiceEmpleado][mascara];
int salarioActual = salarios[indiceEmpleado];
bool respuesta = false;
for (auto posibilidad: formasDeLlegar[salarioActual]) {
if (!(mascara & posibilidad)) {
respuesta |= posible(indiceEmpleado + 1, mascara | posibilidad, salarios, formasDeLlegar, DP);
if (respuesta)
break;
}
}
return DP[indiceEmpleado][mascara] = respuesta;
}
void mascarasASumas(vector<vector<int>> & formasDeLlegar, vector<int> & billetes, int mayorSalario) {
int sumaActual, M = (int) billetes.size();
for (int mascara = 0; mascara < (1<<M); mascara++) {
sumaActual = 0;
for (int i = 0; i < M; i++) {
if (mascara & (1<<i))
sumaActual += billetes[i];
}
if (sumaActual <= mayorSalario)
formasDeLlegar[sumaActual].push_back(mascara);
}
}
bool salariosAlcanzables(vector<int> & salarios, vector<vector<int>> & formasDeLlegar) {
for (auto salario: salarios) {
if (formasDeLlegar[salario].empty())
return false;
}
return true;
}
int main() {
int N, M, mayorSalario;
vector<int> salarios, billetes;
vector<vector<int>> formasDeLlegar;
vector<vector<int>> DP;
cin >> N >> M;
salarios = vector<int>(N);
billetes = vector<int>(M);
DP.assign(N, vector<int>(1<<M, -1));
for (int i = 0; i < N; i++)
cin >> salarios[i];
for (int i = 0; i < M; i++)
cin >> billetes[i];
mayorSalario = *max_element(salarios.begin(), salarios.end());
formasDeLlegar = vector<vector<int>>(mayorSalario+1, vector<int>());
mascarasASumas(formasDeLlegar, billetes, mayorSalario);
if (salariosAlcanzables(salarios, formasDeLlegar) && posible(0, 0, salarios, formasDeLlegar, DP))
cout << "YES";
else
cout << "NO";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'bool posible(int, int, std::vector<int>&, std::vector<std::vector<int> >&, std::vector<std::vector<int> >&)':
bank.cpp:21:37: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
21 | return DP[indiceEmpleado][mascara] = respuesta;
# | 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... |