0

I just saw a kind of algorithm problem like the one below. I don't know how to solve it efficiently so I want to listen to your opinion.


The problem is that you should find the cheapest price to buy certain (at least) quantities of tomatoes when you can only buy with the set like below.

  • Objective : Buy at least 41 tomatoes

  • Set A : 14,000$ with 10 tomatoes (1,400$ per each)

  • Set B : 15,000$ with 8 tomatoes (1,875$ per each)

  • Set C : 12,000$ with 3 tomatoes (4,000$ per each)

I just thought at first that I should buy the cheapest per each set as many as under quantities(in this case, 40), and think about the rest cases (like 1 Set B or 1 Set C...) but it was wrong since the answer was 3 Set A, 1 Set B, 1 Set C (total price 69,000$).

So I wonder if I should consider all possible purchase cases which are over condition quantities to know that. If then, is there any way to know when to stop the case searching (I mean optimization of searching)?

HK S0
  • 404
  • 2
  • 4
  • 14

1 Answers1

1

This is a bin packing / kansack problem. Just google for it.

Jean Valj
  • 119
  • 4
  • Thank you for your answer. I found the dynamic programming solving useful but thought it was slightly different. In a knapsack, there is an upper limit (the size of the knapsack) so we can just stop calculating when we reach the maximum size. But in my case, it doesn’t have an upper limit but a lower limit. So I wonder when to stop calculating using dynamic programming. – HK S0 Jun 12 '22 at 02:24
  • 1
    Then google "knapsack minimum weight". This is the first link : https://stackoverflow.com/questions/65260866/knapsack-with-min-weight – Jean Valj Jun 12 '22 at 05:44