Here is my problem. Imagine I am buying 3 different items, and I have up to 5 coupons. The coupons are interchangeable, but worth different amounts when used on different items.
Here is the matrix which gives the result of spending different numbers of coupons on different items:
coupons: 1 2 3 4 5
item 1 $10 off $15 off
item 2 $5 off $15 off $25 off $35 off
item 3 $2 off
I have manually worked out the best actions for this example:
- If I have 1 coupon, item 1 gets it for $10 off
- If I have 2 coupons, item 1 gets them for $15 off
- If I have 3 coupons, item 1 gets 2, and item 3 gets 1, for $17 off
- If I have 4 coupons, then either:
- Item 1 gets 1 and item 2 gets 3 for a total of $25 off, or
- Item 2 gets all 4 for $25 off.
- If I have 5 coupons, then item 2 gets all 5 for $35 off.
However, I need to develop a general algorithm which will handle different matrices and any number of items and coupons.
I suspect I will need to iterate through every possible combination to find the best price for n coupons. Does anyone here have any ideas?