제출 #679398

#제출 시각아이디문제언어결과실행 시간메모리
679398nicolexxuuKnapsack (NOI18_knapsack)C++14
29 / 100
2 ms212 KiB
#include <bits/stdc++.h> using namespace std; long long S, N; long long dp[2001]; int main() { cin >> S >> N; for(int i = 0; i < N; i++) { // cin >> items[i][0] >> items[i][1] >> items[i][2]; long long V, W, K; cin >> V >> W >> K; for(int i = 1; i <= min(S, K) && i*W <= S; i++) dp[S] = max(dp[S], dp[S-W*i] + V*i); // cout << "starting end val: " << dp[S] << endl; for(int s = S-1; s >= 1; s--) { // cout << "s: " << s << "W:" << W << " K: " << K << endl; // cout << "W*K: " << W*K << endl; int cnt = min(K, s / W); // cout << "why: " << dp[s-W*K] << endl; dp[s] = max(dp[s], dp[s-W*cnt] + V*cnt); // cout << "got here" << endl; } // cout << "hi2" << endl; } cout << dp[S] << endl; } /* 2000 1 5 5 1 9 */
#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...