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<int>> dp(n+1, vector<int>(capacity+1, 0));
// for(int i=1; i<=n; i++){
// for(int j=1; j<=min(2000, copies[i-1]); j++){
// for(int k=1; k<=capacity; k++){
// if(k >= weight[i-1]*j){
// dp[i][k] = max(dp[i-1][k], dp[i-1][k-weight[i-1]*j] + price[i-1]*j);
// }
// else{
// dp[i][k] = dp[i-1][k];
// }
// }
// }
// }
vector<int> dp(capacity+1, 0);
for(int i=0; i<n; i++){
for(int j=1; j<=min(2000, copies[i]); j++){
for(int wt=capacity; wt>=0; wt--){
if(wt > weight[i]*j)
dp[wt] = max(dp[wt], dp[wt-weight[i]*j] + price[i]*j);
}
}
}
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... |