Submission #601398

#TimeUsernameProblemLanguageResultExecution timeMemory
601398codergirlKnapsack (NOI18_knapsack)C++14
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> const int maxn=100005; int c[maxn],value[maxn],num[maxn],dp[maxn]; int V; int main(){ int n; std::cin>>V>>n; // knapsack size V, n kinds of items for(int i=1;i<=n;i++) std::cin>>value[i]>>c[i]>>num[i]; // value, weight, quantity for(int i=1;i<=n;i++) { int k=1; while(k<num[i]){ for(int i=V;i>=k*c[i];i--) { dp[i]=std::max(dp[i],dp[i-k*c[i]] + k*value[i]); } num[i]-=k; k*=2; } for(int i=V;i>=num[i]*c[i];i--) { dp[i]=std::max(dp[i],dp[i-num[i]*c[i]] + num[i]*value[i]); } } std::cout<<dp[V]<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...