# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
981133 | aaaaaarroz | Knapsack (NOI18_knapsack) | C++17 | 116 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()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,w;
cin>>w>>n;
vector<int>valores;
vector<int>pesos;
for(int i=0;i<n;i++){
int v,w,k;
cin>>v>>w>>k;
for(int j=0;j<k;j++){
valores.push_back(v);
pesos.push_back(w);
}
}
vector<vector<int>>dp(valores.size(),vector<int>(w+1,0));
for(int i=0;i<=w;i++){
if(pesos[0]<=i)dp[0][i]=valores[0];
else dp[0][i]=0;
}
for(int i=1;i<valores.size();i++){
for(int j=0;j<=w;j++){
dp[i][j]=dp[i-1][j];
if(pesos[i]<=j){
dp[i][j]=max(dp[i-1][j],valores[i]+dp[i-1][j-pesos[i]]);
}
}
}
cout<<dp[valores.size()-1][w]<<"\n";
return 0;
}
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... |