0-1 Knapsack algorithm

前端 未结 6 981
孤独总比滥情好
孤独总比滥情好 2021-02-09 12:37

Is the following 0-1 Knapsack problem solvable:

  • \'float\' positive values and
  • \'float\' weights (can be positive or negative)
  • \'float\' capacity
6条回答
  •  遇见更好的自我
    2021-02-09 13:07

    If you can only have positive values then every item with a negative weight must go in.

    Then I guess you could calculate Value/Weight Ratio, and brute force the remaining combinations based on that order, once you get one that fits you can skip the rest.

    The problem may be that the grading and sorting is actually more expensive than just doing all the calculations.

    There will obviously be a different breakeven point based on the size and distribution of the set.

提交回复
热议问题