I understand the basics of the 0-1 problem and its solution.
I have a variant of it that I'm trying to solve in a decent way and I'm struggling on it, mostly because of the 0-weighted items. These are the rules:
- I have k finite sets of items. Each item has a weight and a value.
- I must take exactly one item from each set.
- Zero-weighted items are allowed. But since you are not allowed to take more than one item from each set, it's not always convenient to take them.
- Weights in each set are the first natural numbers {0, 1, 2, 3...i}.
- In each set, values are non-decreasing when the weight increases.
- I want to determine which items maximize the total value for a certain total weigth.
example:
Set | Weight 0 | Weight 1 | Weight 2 | Weight 3 | Weight 4 | Weight 5 |
---|---|---|---|---|---|---|
A | 3 | 6 | 6 | 9 | 15 | 26 |
B | 0 | 6 | 8 | - | - | - |
C | 1 | 1 | 10 | 15 | 16 | - |
The notation "B3" means "Select the object from set B that weights 3".
The solutions for a maximum total weight = n are:
- n=0 -> [A0; B0; C0] => Total Value = 4
- n=1 -> [A0; B1; C0] => Total Value = 10
- n=2 -> [A0; B0; C2] OR [A1;B1;C0] => Total Value = 13
- n=3 -> [A0; B1; C2] => Total Value = 19
- n=4 -> [A0; B1; C3] => Total Value = 24
- n=5 -> [A1; B1; C3] OR [A5;B0;C0] => Total Value = 27
- n=6 -> [A5; B1; C0] => Total Value = 33
- n=7 -> [A5; B0; C2] => Total Value = 36
- n=8 -> [A5; B1; C2] => Total Value = 42
- n=9 -> [A5; B1; C3] => Total Value = 47
- n=10-> [A5; B2; C3] => Total Value = 49
- n=11-> [A5; B2; C4] => Total Value = 50
- n>=12 it's the same as n=11.
Do you have some clue for implementing a decent algorithm to find the best combination of items to solve this problem with a generic collection of such set? Thanks!