제출 #876136

#제출 시각아이디문제언어결과실행 시간메모리
876136CBG6682Knapsack (NOI18_knapsack)C++17
12 / 100
9 ms12636 KiB
#include <bits/stdc++.h> using namespace std; const int MAXX = 1e5 + 5; int s,n,v[MAXX],w[MAXX],dp[2001][MAXX],k[MAXX]; int main(){ cin >> s >> n; for (int i = 0; i < n; i++) cin >> v[i] >> w[i] >> k[i]; for (int i = 1; i <= s; i++){ for (int j = 0; j < n; j++){ if (i >= w[j]){ int num = 1; while (num*w[j] <= i && num <= k[j]){ dp[i][j] = max(max(dp[i - num*w[j]][j - 1] + v[j]*num,dp[i][j]),max(dp[i - 1][j],dp[i][j - 1])); dp[i][j] = max(dp[i][j],dp[i-1][j - 1]); num++; } } } } cout << dp[s][n - 1]; 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...