What's the fastest way to solve knapsack prob with two properties

泄露秘密 提交于 2019-12-01 22:16:41

You can use the same approach of knapsack problem, but instead of 2D matrix, you will have a 3D table, a dimension for each parameter (2 constraint + index).

The recursive formula will be similar, but of course will be done for both parameters.

f(item,cost1,cost2) = max {
               f(item-1,cost1,cost2), 
               f(item,cost1-firstCost[i],cost2-secondCost[i]) + profit[i]
                          }

(Base clauses will be similar as well, but with an extra dimension.)

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