제출 #970733

#제출 시각아이디문제언어결과실행 시간메모리
97073354skyxenonKnapsack (NOI18_knapsack)C++17
0 / 100
2 ms348 KiB
// https://oj.uz/problem/view/NOI18_knapsack #include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int s, n; cin >> s >> n; vector<tuple<int, int, int>> items; for (int i = 0; i < n; i++) { int v, w, k; cin >> v >> w >> k; items.push_back({v, w, k}); } vector<int> past_dp(s + 1); for (int i = 0; i < n; i++) { auto [v, w, k] = items[i]; vector<int> dp(s + 1); for (int j = 1; j <= s; j++) { int repeat = j / w; // for (int repeat = 1; repeat <= k && repeat * w <= j; repeat++) { dp[j] = max(dp[j], repeat * v + past_dp[j - repeat * w]); // } } for (int j = 1; j <= s; j++) { past_dp[j] = max(past_dp[j], dp[j]); } } cout << past_dp[s] << '\n'; }
#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...