제출 #970712

#제출 시각아이디문제언어결과실행 시간메모리
97071254skyxenonKnapsack (NOI18_knapsack)C++17
12 / 100
1 ms348 KiB
// https://oj.uz/problem/view/NOI18_knapsack #include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int s, n; cin >> s >> n; vector<tuple<int, int, int>> items; for (int i = 0; i < n; i++) { int v, w, k; cin >> v >> w >> k; items.push_back({v, w, k}); } vector<vector<int>> dp(n + 1, vector<int>(s + 1)); for (int i = 0; i <= n; i++) { for (int j = 0; j <= s; j++) { if (i == 0 || j == 0) { continue; } int opt = 0; for (int repeat = 1; repeat <= get<2>(items[i - 1]); repeat++) { int cost = repeat * get<1>(items[i - 1]); if (cost > j) { break; } opt = max(opt, get<0>(items[i - 1]) * repeat + dp[i - 1][j - cost]); } dp[i][j] = opt; } } cout << dp[n][s] << '\n'; }
#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...