how to understand about reducing time complexity on 0~1 knapsack

这一生的挚爱 提交于 2019-12-25 00:17:03

问题


As for 0~1 knapsack problem,

f[i][v]=max{f[i-1][v],f[i-1][v-c[i]]+w[i]}

c[i] means the cost of ith goods, w[i] means the value of ith goods.

And I read one doc,which said the time complexity can be optimization,especially when V is larger.as below

 i=1...N

 v=V...0 

can be changed to

 i=1...n        

bound=max{V-sum{w[i..n]},c[i]}        

 v=V...bound

what does it mean?How can V(the maximum of bag) minus sum of w[i](the value of goods)?

Really confuse,or something wrong on this doc?


回答1:


You didn't say whose complexity you are optimizing. Are you using dynamic programming? If so, this could mean that you don't need to calculate f[i][v] for small values of v, because you won't need those values to find the optimum.

Even if you put all goods from i + 1 to n in the knapsack, you still have a capacity of V - sum{c[i+1..n]} left, so you don't need to solve the subproblem i (restricted to goods 1..i) with a capacity smaller than that.

If you need a more formal answer, please describe the problem, as well as the algorithm being used, with more details.



来源:https://stackoverflow.com/questions/14242909/how-to-understand-about-reducing-time-complexity-on-01-knapsack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!