Submission #601422

#TimeUsernameProblemLanguageResultExecution timeMemory
601422codergirlKnapsack (NOI18_knapsack)C++14
73 / 100
1095 ms2636 KiB
#include<bits/stdc++.h> const int maxn=100005; long c[maxn],value[maxn],num[maxn], dp[maxn]; int V; void ZeroOnePack (long cost,long val){ for(long i=V;i>=cost;i--) { dp[i]=std::max(dp[i],dp[i-cost] + 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++) { long k=1; while(k<num[i]){ ZeroOnePack(k * c[i], k * value[i]); num[i]-=k; k*=2; } ZeroOnePack(num[i]*c[i],num[i]*value[i]); } std::cout<<dp[V]<<'\n'; }
#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...