0-1 Knapsack algorithm

前端 未结 6 2091
花落未央
花落未央 2021-02-09 12:35

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 12:57

    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.

提交回复
热议问题