제출 #491168

#제출 시각아이디문제언어결과실행 시간메모리
491168tarcheKnapsack (NOI18_knapsack)C++17
12 / 100
2 ms1740 KiB
#include <bits/stdc++.h> using namespace std; int main() { int S, N; cin >> S >> N; vector<int> value(N), weight(N), amount(N); for (int i = 0; i < N; i++) cin >> value[i] >> weight[i] >> amount[i]; vector<vector<pair<int, int>>> dp(N, vector<pair<int, int>>(S + 1)); for (int i = 0; i < N; i++) { for (int j = 0; j <= S; j++) { int k = j + weight[i]; if (dp[i][j].second < amount[i] && k <= S) { if (dp[i][k].first < dp[i][j].first + value[i]) { dp[i][k].first = dp[i][j].first + value[i]; dp[i][k].second = dp[i][j].second + 1; } } if (i < N - 1 && dp[i + 1][j].first < dp[i][j].first) { dp[i + 1][j].first = dp[i][j].first; } } } int ans = 0; for (int i = 0; i < N; i++) for (int j = 0; j <= S; j++) ans = max(ans, dp[i][j].first); cout << ans << '\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...