# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1014516 | dizzytaps | Knapsack (NOI18_knapsack) | C++14 | 120 ms | 262144 KiB |
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 <bits/stdc++.h>
using namespace std;
int main(){
int s,n;
cin>>s>>n;
vector<int> values;
vector<int> weights;
for(int i=0;i<n;i++){
int val,weight,k;
cin>>val>>weight>>k;
for(int i=0;i<k;i++){
values.push_back(val);
weights.push_back(weight);
}
}
vector<vector<int>> dp(s+1,vector<int>(values.size()+1,0));
for(int i=1;i<=s;i++){
for(int j=1;j<=values.size();j++){
dp[i][j]=dp[i][j-1];
if(i-weights[j-1]>=0) dp[i][j]=max(dp[i][j],dp[i-weights[j-1]][j-1]+values[j-1]);
}
}
cout<<dp[s][values.size()]<<endl;
}
Compilation message (stderr)
# | 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... |