제출 #856561

#제출 시각아이디문제언어결과실행 시간메모리
856561owenlolKnapsack (NOI18_knapsack)C++17
0 / 100
1 ms1116 KiB
#include <bits/stdc++.h> using namespace std; int main() { int S, N; cin >> S >> N; vector<int> ws; vector<int> vs; vector<int> ks; for (int i=0; i<N; i++) { int v, w, k; cin >> v >> w >> k; vs.push_back(v); ws.push_back(w); ks.push_back(k); } vector<vector<int>> dp(S+1, vector<int>(N+1)); for (int i=0; i<S; i++) { dp[i][0] = 0; } for (int i=0; i<N; i++) { dp[0][i] = 0; } for (int s=1; s<S+1; s++) { for (int i=1; i<N+1; i++) { for (int r=1; r<=ks[i]; r++) { if (s >= r*ws[i]) { dp[s][i] = max(dp[s][i], dp[s-r*ws[i]][i-1] + r*vs[i]); } } dp[s][i] = max(dp[s][i], dp[s][i-1]); } } cout << dp[S][N]; return 0; }
#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...