Submission #601187

#TimeUsernameProblemLanguageResultExecution timeMemory
601187codergirlKnapsack (NOI18_knapsack)C++14
37 / 100
2 ms468 KiB
#include <bits/stdc++.h> const int maxn=100005; int c[maxn],value[maxn],num[maxn]; int dp[maxn]; int V; void ZeroOnePack (int cost,int val){ for(int i=V;i>=cost;i--) dp[i]=std::max(dp[i],dp[i-cost] + val); return ; } void MultiplePack(int cost, int val, int tot){ int k=1; while(k<tot){ ZeroOnePack(k * cost, k * val); tot=tot-k; k=k*2; } ZeroOnePack(tot*cost,tot*val); return ; } 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]; // weight, value, quantity for(int i=1;i<=n;i++) MultiplePack(c[i], value[i], num[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...