이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int unboundedKnapsackWithLimits(vector<int>& weights, vector<int>& values, vector<int>& limits, int W) {
int n = weights.size();
vector<vector<int>> dp(n + 1, vector<int>(W + 1, 0));
for (int i = 1; i <= n; ++i) {
for (int w = 1; w <= W; ++w) {
dp[i][w] = dp[i - 1][w];
for (int j = 1; j <= min(limits[i - 1], w / weights[i - 1]); ++j) {
dp[i][w] = max(dp[i][w], dp[i - 1][w - j * weights[i - 1]] + j * values[i - 1]);
}
}
}
return dp[n][W];
}
int main() {
int z1, z2, z3, W, n;
cin >> W >> n;
vector<int> values, weights, limits;
while (n--) {
cin >> z1 >> z2 >> z3;
values.push_back(z1);
weights.push_back(z2);
limits.push_back(z3);
}
cout << unboundedKnapsackWithLimits(weights, values, limits, W) << 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |