제출 #925483

#제출 시각아이디문제언어결과실행 시간메모리
925483Youssif_ElkadiKnapsack (NOI18_knapsack)C++17
73 / 100
131 ms3036 KiB
#include <bits/stdc++.h> using namespace std; const int N = 5e2 + 5, inf = 1e9, mod = 998244353; int dp[106][2005], s, n; pair<int, pair<int, int>> arr[105]; int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); cin >> s >> n; for (int i = 1; i <= n; i++) cin >> arr[i].first >> arr[i].second.first >> arr[i].second.second; for (int i = 1; i <= n; i++) for (int j = 0; j <= s; j++) dp[i][j] = -inf; for (int i = 1; i <= n; i++) for (int j = 0; j <= s; j++) for (int k = 0; k <= arr[i].second.second && k * arr[i].second.first <= j; k++) dp[i][j] = max(dp[i][j], dp[i - 1][j - k * arr[i].second.first] + arr[i].first * k); 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...