제출 #1061444

#제출 시각아이디문제언어결과실행 시간메모리
1061444voiKnapsack (NOI18_knapsack)C++17
73 / 100
96 ms3160 KiB
#include <bits/stdc++.h> using namespace std; int n, m, w[105], a[105], v[105], dp[105][10005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> m >> n; for(int i = 1; i <= n; ++i) { cin >> v[i] >> w[i] >> a[i]; } for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) { dp[i][j] = dp[i - 1][j]; for(int k = 1, lim = min(a[i], j / w[i]); k <= lim; ++k) dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i] * k] + v[i] * k); } cout << (*max_element(dp[n] + 1, dp[n] + m + 1)); 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...