Submission #658958

#TimeUsernameProblemLanguageResultExecution timeMemory
658958NONTACKnapsack (NOI18_knapsack)C++11
37 / 100
65 ms55708 KiB
#include <bits/stdc++.h> using namespace std; int n, s; vector<int> item; vector<int> weight; int dp[1001][2001]; void print() { for(int i = 1; i < n; i++){ for(int j = 0; j <= s; j++) cout<<dp[i][j]<<" "; cout<<endl; } } int main() { cin>>s>>n; item.push_back(0); weight.push_back(0); for(int i = 0; i < n; i++){ int v, w, k; cin>>v>>w>>k; while(k--){ item.push_back(v); weight.push_back(w); } } n = item.size(); for(int i = 1; i < n; i++){ int w = weight[i], v = item[i]; for(int j = 1; j <= s; j++){ dp[i][j] = dp[i - 1][j]; if(j - w >= 0) dp[i][j] = max(dp[i][j], dp[i - 1][j - w] + v); } } //print(); cout<<dp[n - 1][s]; 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...