이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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];
}
}
}
}
cout << dp[n][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... |