제출 #1109321

#제출 시각아이디문제언어결과실행 시간메모리
1109321greenbinjackKnapsack (NOI18_knapsack)C++17
17 / 100
9 ms7916 KiB
#include <bits/stdc++.h> using namespace std; #define all(v) v.begin(), v.end() using LL = long long; int main() { cin.tie(nullptr)->ios_base::sync_with_stdio(false); int s, n; cin >> s >> n; vector <int> weight, val; for (int i = 0; i < n; i++) { int v, w, k; cin >> v >> w >> k; for (int j = 1; j * w <= s and j <= k; j++) { weight.push_back (j * w); val.push_back (v); } } n = weight.size (); vector < vector <int> > dp (n + 1, vector <int> (s + 1)); for (int i = 1; i <= n; i++) { for (int j = s; j >= 0; j--) { dp[i][j] = dp[i - 1][j]; if (j - weight[i - 1] >= 0) dp[i][j] = max (dp[i][j], dp[i - 1][j - weight[i - 1]] + val[i - 1]); } } cout << *max_element (all (dp[n])) << '\n'; 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...