제출 #1278213

#제출 시각아이디문제언어결과실행 시간메모리
12782131anKnapsack (NOI18_knapsack)C++20
73 / 100
382 ms327680 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main () { int s, n; cin >> s >> n; vector<int> v(n), w(n), k(n); for (int i = 0; i < n; i++) cin >> v[i] >> w[i] >> k[i]; vector<vector<int>> dp(n, vector<int>(s + 1)); for (int i = 1; i <= min(s / w[0], k[0]); i++) dp[0][i * w[0]] = i * v[0]; for (int i = 1; i < n; i++) { dp[i][0] = 0; // base case for (int j = 0; j <= s; j++) { dp[i][j] = dp[i - 1][j]; for (int t = 1; t <= min(j / w[i], k[i]); t++) { dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i] * t] + v[i] * t); } } } int res = 0; for (int i = 0; i <= s; i++) res = max(res, dp[n - 1][i]); printf("%lld\n", res); }
#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...