Submission #592820

#TimeUsernameProblemLanguageResultExecution timeMemory
592820mjayKnapsack (NOI18_knapsack)C++11
37 / 100
123 ms262144 KiB
#include <bits/stdc++.h> using namespace std; int main(){ int S, N; cin >> S >> N; vector<int> values, weights; for(int i=0; i<N; i++){ int value, weight, freq; cin >> value >> weight >> freq; while(freq--){ values.push_back(value); weights.push_back(weight); } } N = weights.size(); vector<vector<int>> dp(N+1, vector<int>(S+1, 0)); for(int i=1; i<=N; i++){ for(int j=0; j<=S; j++){ dp[i][j] = dp[i-1][j]; int left = j - weights[i-1]; if(left >= 0) dp[i][j] = max(dp[i][j], dp[i-1][left] + values[i-1]); } } cout << dp[N][S] << 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...