제출 #925479

#제출 시각아이디문제언어결과실행 시간메모리
925479Youssif_ElkadiKnapsack (NOI18_knapsack)C++17
0 / 100
2 ms1368 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() { 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 = 0; i <= s; i++) for (int j = 0; j <= n; j++) dp[i][j] = -inf; dp[0][0] = 0; 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...