Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
279 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...