제출 #756383

#제출 시각아이디문제언어결과실행 시간메모리
756383asdasdqwerKnapsack (NOI18_knapsack)C++14
12 / 100
1 ms468 KiB
#include <bits/stdc++.h> using namespace std; int main() { int s, n; cin >> s >> n; vector<int64_t> dp(s+1, 0); vector<int> div(s+1); if (n == 1) { int64_t v, w, k; cin >> v >> w >> k; int times = min(s / w, k); cout << v * times << "\n"; return 0; } // calculate div for (int i = 1; i <= s; i++) { div[i] = s / i; } vector<vector<int>> value(s+1); for (int i = 1; i <= s; i++) { value[i] = vector<int>(div[i], 0); } for (int i = 0; i < n; i++) { int v, w, k; cin >> v >> w >> k; int m = min(div[w], k); for (int j = 0; j < m; j++) { value[w][j] = max(value[w][j], v); } } for (int i = s; i > 0; i--) { for (int j = 0; j < div[i]; j++) { int v = value[i][j]; if (v == 0) break; for (int k = s; k > 0; k--) { if ((k - i) >= 0) { dp[k] = max(dp[k], dp[k - i] + v); } } } } cout << 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...