Submission #601446

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