Submission #785933

#TimeUsernameProblemLanguageResultExecution timeMemory
785933rainyhawkKnapsack (NOI18_knapsack)C++17
73 / 100
152 ms262144 KiB
#include <iostream> #include <algorithm> using namespace std; int main(){ int s, n, ans = 0; cin >> s >> n; int v[n], w[n], k[n]; int dp[n+1][s+1]; for(int i = 0; i < n; i++) cin >> v[i] >> w[i] >> k[i]; for(int i = 0; i <= n; i++){ for(int j = 0; j<= s; j++){ dp[i][j] = -1; } } dp[0][0] = 0; for(int i = 0; i < n; i++){ for(int j = 0; j<= s; j++){ if (dp[i][j] == -1) continue; for(int l = 0; l <= k[i]; l++){ if (j+l*w[i] > s) break; dp[i+1][j+l*w[i]] = max(dp[i+1][j+l*w[i]], dp[i][j] + l*v[i]); ans = max (ans, dp[i+1][j+l*w[i]]); } } } cout << ans << endl; }
#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...