제출 #1179456

#제출 시각아이디문제언어결과실행 시간메모리
1179456GoBananas69Knapsack (NOI18_knapsack)C++20
49 / 100
129 ms327680 KiB
#include <algorithm> #include <chrono> #include <iostream> #include <vector> using namespace std; typedef long long ll; int main() { cin.tie(0)->sync_with_stdio(0); int s, n; cin >> s >> n; vector<int> v(1, 0), w(1, 0); for (int i = 0; i < n; ++i) { int a, b, c; cin >> a >> b >> c; for (int j = 0; j < min(c, 2000); ++j) { v.push_back(a); w.push_back(b); } } n = v.size() - 1; 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) { if (i == 0 || j == 0) { dp[i][j] = 0; continue; } if (w[i] > j) { dp[i][j] = dp[i - 1][j]; } else { dp[i][j] = max(dp[i - 1][j], v[i] + dp[i - 1][j - w[i]]); } } } 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...