제출 #1061441

#제출 시각아이디문제언어결과실행 시간메모리
1061441voiKnapsack (NOI18_knapsack)C++17
0 / 100
1 ms2652 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 >> w[i] >> v[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...