简体   繁体   English

如何减少0〜1背包的时间复杂度

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

As for 0~1 knapsack problem, 至于0〜1背包问题,

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. c [i]表示第i种商品的成本,w [i]表示第i种商品的价值。

And I read one doc,which said the time complexity can be optimization,especially when V is larger.as below 我读了一个文档,说时间复杂度可以优化,尤其是当V较大时。

 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)? 这是什么意思?V(袋的最大值)如何减去w [i](商品的价值)之和?

Really confuse,or something wrong on this doc? 真的感到困惑,还是这个文档有问题?

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. 如果是这样,这可能意味着您不需要为f[i][v]的较小值计算f[i][v] ,因为您不需要这些值即可找到最佳值。

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. 即使将所有从i + 1n商品放入背包,您仍然可以得到V - sum{c[i+1..n]}的容量,因此您不需要解决子问题i (限于容量小于1..i商品。

If you need a more formal answer, please describe the problem, as well as the algorithm being used, with more details. 如果您需要更正式的答案,请详细描述问题以及所使用的算法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM