제출 #974734

#제출 시각아이디문제언어결과실행 시간메모리
974734vjudge1Knapsack (NOI18_knapsack)C++17
73 / 100
760 ms262144 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...