Let’s say you are in a magical supermarket on another planet. And the rules on this planet are that you only pay 1 Schmeckle for each type of ingredient in your shopping basket.
So let’s say your shopping list is:
- Chocolate cake (contains chocolate, butter, sugar)
- Sugar
- Banana
- Banana yoghurt (contains milk, sugar, banana)
- Butter
- Milk
- Strawberry milk (contains strawberry and milk)
- 1000 other things (coz you’re gonna throw a big party)
The chocolate cake contains sugar and butter so if you put the chocolate cake in the first basket, then you can also get the sugar and butter FOR FREE, as long as they are in the same basket!
But now if you put chocolate cake, sugar, and butter in Basket A, you realize the the banana yoghurt contains sugar. So if you add the banana yoghurt, you only need to pay for the milk ingredient part — and now if you add milk and banana, you get them for free, etc.
Now further suppose that the baskets are magical or something (I can’t really come up with a good physical analogy for this, so just use your imagination!) — they can contain any number of items, but can only contain up to M ingredients total. So for example, with M=5, if you add chocolate cake, and then sugar and butter that's 3 ingredients total; then you can add banana yoghurt, milk and banana, for a total of 5 ingredients -- so now you can't add the strawberry milk, as you are up the the maximum number of M ingredients per basket.
You can use as many baskets as you want, but the ingredient discount only applies per basket. So if you have sugar in two baskets, you will pay 1 Schmeckle for each sugar in each basket. In the above example, if you add strawberry milk to Basket B, you must now pay 1 Schmeckle each for milk and strawberry.
Now the problem statement is — what is the best way to distribute all the food on your shopping list among the baskets, in order to minimize the total cost at the checkout?
Easy version: Assume that you can use as many baskets as you want.
Difficult version: Assume that you are limited to N baskets, and you want to fill all the baskets.
EDIT: clarified example and formatting
Subreddit
Post Details
- Posted
- 6 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/algorithms/...