Knapsack with limit on total items used

不打扰是莪最后的温柔 提交于 2019-12-04 17:12:19

This is the multiply constrained knapsack problem. Your new constraint is that the sum of the number of items is less than some number unrelated to their weight.

There's some good approaches in here: http://www2.math.uni-wuppertal.de/~klamroth/publications/klwidp00.pdf

You should also try adapting the recurrence relation of the regular knapsack problems with your new constraint and see where you get.

This can be formulated as a multiply constrained knapsack problem (also known as multidimensional knapsack problem) as follows.

The objective function and the first dimension remain the same as in your current formulation (i.e. the sum of weights).

The second dimension can then be used to constrain the number of selected items. Using Wikipedia notation:

  • w2,i = 1 for all i;
  • W2 = the limit on the number of items you're allowed to select (in your example, 5).

Here are some references:

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