제출 #780272

#제출 시각아이디문제언어결과실행 시간메모리
780272makanhuliaKnapsack (NOI18_knapsack)C++17
49 / 100
1085 ms1888 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int t, n, val[100005], cost[100005], remain[100005], dp[100005][2005]; signed main() { cin >> t >> n; for (int i = 1; i <= n; i++) cin >> val[i] >> cost[i] >> remain[i]; if (n == 1) { int count = (t/cost[1]); count = min(count, remain[1]); cout << count*val[1] << endl; return 0; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= t; j++) { dp[i][j] = dp[i-1][j]; for (int k = 1; k <= remain[i]; k++) { if (j >= cost[i]*k) { dp[i][j] = max(dp[i][j], dp[i-1][j-cost[i]*k]+val[i]*k); } } } } // for (int i = 1; i <= n; i++) { // for (int j = 0; j <= t; j++) { // cout << dp[i][j] << " "; // } // cout << endl; // } cout << dp[n][t] << endl; }
#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...