Submission #798668

#TimeUsernameProblemLanguageResultExecution timeMemory
798668gustavo_dKnapsack (NOI18_knapsack)C++17
29 / 100
26 ms28992 KiB
// https://oj.uz/problem/view/NOI18_knapsack > p83 #include <bits/stdc++.h> using namespace std; vector<vector<vector<int>>> dp(101, vector<vector<int>> (2001)); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int S, n; cin >> S >> n; vector<int> v(n); vector<int> w(n); vector<int> K(n); for (int i=0; i<n; i++) cin >> v[i] >> w[i] >> K[i]; int mx = 0; for (int i=0; i<n; i++) { K[i] = min(K[i], (S/w[i])+min(S%w[i], 1)); mx = max(mx, K[i]); } for (int i=n; i>=0; i--) { for (int P=0; P<=S; P++) { dp[i][P] = vector<int> (mx, 0); } } K.push_back(0); for (int i=n-1; i>=0; i--) { for (int P=0; P<=S; P++) { for (int k=0; k<=mx; k++) { dp[i][P][k] = dp[i+1][P][K[i+1]]; if (k>0 and P>=w[i]) { dp[i][P][k] = max( dp[i][P][k], dp[i][P-w[i]][k-1] + v[i] ); } } } } cout << dp[0][S][K[0]] << endl; 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...