제출 #779436

#제출 시각아이디문제언어결과실행 시간메모리
779436mydeKnapsack (NOI18_knapsack)C++17
49 / 100
84 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int s, n, v, w, k; vector<pair<int, int>> items; signed main() { cin >> s >> n; // pair<int, pair<int, int>> p[n + 1]; for (int i = 1; i <= n; i++) { // cin >> p[i].first >> p[i].second.first >> p[i].second.second; cin >> v >> w >> k; for (int j = 1; j <= min(k, (s + w - 1) / w); j++) { items.push_back({v, w}); } } n = items.size(); int dp[n + 1][s + 1]; for (int i = 0; i <= s; i++) dp[0][i] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= s; j++) { dp[i][j] = dp[i - 1][j]; if (j >= items[i - 1].second) { dp[i][j] = max(dp[i][j], dp[i - 1][j - items[i - 1].second] + items[i - 1].first); } // cout << ":: " << i << ' ' << j << ' ' << dp[i][j] << '\n'; } } 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...