I have items with ID 1, 3, 4, 5, 6, 7
. Now I have data like following.
There is an offerId for each row. Array of Ids
consist of combination of the ID
in an array. Discount
is the value for that offerId
offerId : Array of Ids : Discount
o1 : [1] : 45
o2 : [1 3 4] : 100
o3 : [3 5] : 55
o4 : [5] : 40
o5 : [6] : 30
o6 : [6 7] : 20
Now I have to select all the offerIds which give me best combination of Ids i.e. maximum total discount.
For example in above case : possible results can be:
[o2, o4, o5] maximum discount is 170(100 + 40 + 30)
.
Note. the result offerId should be such that Ids don't repeat. Example for o2,o4,o6
ids are [1,3,4], [5], [6] all are distinct.
Other combination can be :
o1, o3, 06
for which ids are [1], [3,5], [6,7] However the total is 120(45+55+20) which is less then 170
as in previous case.
I need an algorithm/code which will help me to identify combination of offerIds
which will give maximum discount
, considering that each offer should contain distinct Ids
.
NOTE I am writing my code in go
language. But solutions/Logic in any language will be helpful.
NOTE : I hope I am able to explain my requirement properly. please comment if any extra information is required. Thanks.