I have a set of N
numbers with some cost attached to each number, and the problem is to choose all possible set of numbers as a list such that their product is less than a certain number M
, sorted according to the sum of cost.
Eg :- The set of numbers is
(number, costOfThatNumber) : {(90, 10) , (80, 20), (60, 40), (40, 60), (15, 85)},
and the Product must be less than, Prod <= 1000
,
Possible solutions are :-
[Solution 1 :- {(15, 85), (40, 60)} :- Product = 600 (which is less than, 1000), cost = 85 + 60 = 145]
[Solution 2 :- {(15, 85), (80, 20)} :- Product = 900 and cost = 105]
So the list becomes, {Solution2, Solution1}
.
PS :-
- This is not a homework problem, it was asked in an interview. I was asked only the algorithm, all i could say was that it looks kinda similar to knapsack problem, but for multiplication.
- Please excuse if i am unable to explain the problem properly.