This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
using namespace std;
int main(){
int capacity, n;
cin >> capacity >> n;
vector<int> price(n), weight(n), copies(n);
for(int i=0; i<n; i++){
cin >> price[i] >> weight[i] >> copies[i];
}
// // dp[i][j] tells us the maximum profit we can achieve using
// // a subcollection of first i elements, with j weight
// vector<vector<vector<int>>> dp(n+1, vector<vector<int>>(2001, vector<int>(capacity+1, 0)));
// for(int i=0; i<n; i++){
// for(int j=1; j<=2000; j++){
// for(int k=1; k<=capacity; k++){
// if(k >= weight[i]){
// dp[i][j][k] = max(dp[i][j-1][k], dp[i][j-1][k-weight[i]] + price[i]);
// }
// else{
// dp[i][j][k] = dp[i][j-1][k];
// }
// }
// }
// }
vector<int> dp(capacity+1, 0);
for(int i=0; i<n; i++){
for(int j=1; j<=copies[i]; j++){
for(int wt=capacity; wt>=0; wt--){
if(wt >= weight[i])
dp[wt] = max(dp[wt], dp[wt-weight[i]] + price[i]);
else
break;
}
}
}
// int ans=0;
// for(int i=0; i<=2000; i++)
// ans = max(ans, dp[n-1][i][capacity]);
// cout << ans << endl;
cout << dp[capacity] << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |