이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
struct item {
int value;
int weight;
int amount;
};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int S,N;
cin >> S >> N;
vector<item> itemTypes(N+1,item());
int totalItems=0;
for(int i=0;i<N;i++){
cin >> itemTypes[i].value >> itemTypes[i].weight >> itemTypes[i].amount;
totalItems+=itemTypes[i].amount;
}
vector<int> dp(S+1,0); //max value for [i(this weight)][j(how many used)]
vector<int> dpAfter(S+1,0); //max value for [i(this weight)][j(how many used)]
int currentItemIndex = 0;
item currentItem = itemTypes[currentItemIndex];
int count=0;
int maxValue=0;
// cout << "GO\n";
for(int item=0;item<totalItems;item++){
// cout << "dping on "<<currentItemIndex<<endl;
for(int i=0;i<S;i++){
// dp[i]=max(dp[i],dp[i]);
if(i+currentItem.weight<=S){
// cout << "i"<<i<<"+weight("<<currentItem.weight<<") <= "<<S<<endl;
dpAfter[i+currentItem.weight]=max(dpAfter[i+currentItem.weight],dp[i]+currentItem.value);
maxValue=max(maxValue,dpAfter[i+currentItem.weight]);
}
// cout << "i is now "<<i<<endl;
}
for(int i=0;i<S+1;i++){
dp[i]=dpAfter[i];
}
// fill(dpAfter.begin(),dpAfter.end(),0);
count++;
if(count==currentItem.amount){
count=0;
currentItemIndex++;
currentItem = itemTypes[currentItemIndex];
}
}
cout << maxValue << "\n";
}
# | 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... |