Submission #974903

#TimeUsernameProblemLanguageResultExecution timeMemory
974903vjudge1Knapsack (NOI18_knapsack)C++17
73 / 100
760 ms262144 KiB
#include <bits/stdc++.h> using namespace std; int knapsack(int S, const vector<int> &V, const vector<int> &W, const vector<int> &K) { int N = V.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++) { for (int k = 0; k <= min(j / W[i - 1], K[i - 1]); ++k) { dp[i][j] = max(dp[i][j], dp[i - 1][j - k * W[i - 1]] + k * V[i - 1]); } } } return dp[N][S]; } void solve() { int s, n; cin >> s >> n; vector<int> v(n), w(n), k(n); for (int i = 0; i < n; i++) { cin >> v[i] >> w[i] >> k[i]; } cout << knapsack(s, v, w, k); } int main() { int t = 1; while (t--) { solve(); } 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...