Finding cheapest combination of items with conditions on the selection

前端 未结 2 1409
生来不讨喜
生来不讨喜 2021-01-13 05:50

Lets say that I have 3 sellers of a particular item. Each seller has different amounts of this items stored. The also have a different price for the item.



        
2条回答
  •  暖寄归人
    2021-01-13 06:03

    This is a Bounded Knapsack problem. Where you want to optimize(minimize) the cost with the constraints of price and quantity.

    Read about 0-1 KnapSack problem here. Where you have only 1 quantity for given supplier.

    Read how to extend the 0-1 KnapSack problem for given quantity ( called Bounded Knapsack ) here

    A more detailed discussion of Bounded KnapSack is here

    These all will be sufficient to come up with an algorithm which requires a bit of tweaking ( i.g. adding 5$ when the quantity is below some given quantity )

提交回复
热议问题