0-1 Knapsack with additional restriction (colored items)?

别来无恙 提交于 2019-12-08 02:41:35

问题


I'm working on this problem mostly out of curiosity in my downtime at work.

Imagine the normal 0-1 Knapsack problem, except all the items are either yellow, red, blue, or green, and due to your OCD you must have exactly 2 items of each color in your knapsack. So instead of the normal items each item has 3 properties: Weight, Value, Color.

Is this even still a knapsack problem, or is it better define in some other way?


回答1:


I'll use nCk to represent "n choose k" for ease of typing. Since you must have exactly 2 items of each color, the number of feasible solutions is O(nC2), which is O(n^2). Each solution can be evaluated in polynomial time, so the problem is solvable in polynomial time as well. In other words, it's far simpler than a regular knapsack problem.



来源:https://stackoverflow.com/questions/13481516/0-1-knapsack-with-additional-restriction-colored-items

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