이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
struct Item {
int value, weight, amount;
};
int solve(const vector<Item>& items, vector<vector<int>>& dp, int i, int j, int k) {
if (i < 0 || j < 0 || k < 0)
return -INF;
if (dp[i][j] != -1)
return dp[i][j];
int lhs = solve(items, dp, i, j - items[i].weight, k - 1) + items[i].value;
int rhs = solve(items, dp, i - 1, j, items[i - 1].amount);
dp[i][j] = max(lhs, rhs);
cout << i << ' ' << j << ' ' << k << " : " << lhs << ", " << rhs << '\n';
return dp[i][j];
}
int main() {
int S, N;
cin >> S >> N;
vector<Item> items(N);
for (int i = 0; i < N; i++)
cin >> items[i].value >> items[i].weight >> items[i].amount;
sort(items.begin(), items.end(), [&](const Item& lhs, const Item& rhs) {
return lhs.value < rhs.value;
});
vector<vector<int>> dp(N, vector<int>(S + 1, -1));
dp[0][0] = 0;
int ans = solve(items, dp, N - 1, S, items[N - 1].amount);
for (int i = 0; i < N; i++) {
for (int j = 0; j <= S; j++) {
cout << dp[i][j] << ' ';
}
cout << '\n';
}
cout << ans << '\n';
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |