Context
- I have a list of items
- I also have a structure with s stages
- The number of stages of stages can be larger, equals or less than the number of items
- Each stage can have n slots
- Items can ocupy the same stage by take 2 slots in that stage
- The slots’ order is irrelevant
- The number of slots is less or equal to the number items
- Each slot can contain one item
- A slot can be empty
- Any given structure can only contain each item once
Problem:
I want to generate all the combinations for the distribution of items in structure, such that:
- Each item appears once and only once in the structure
- All items are present in each combination
- I want to use Java for the implementation
Example:
/* Inputs */
items = {1, 2}
structure = [ {}, {}, {}] // with 3 stages
/* Outputs */
comb1 = [ {1,2}, {}, {} ]
comb2 = [ {1}, {2}, {} ]
comb3 = [ {1}, {}, {2} ]
comb4 = [ {}, {1,2}, {} ]
comb5 = [ {}, {1}, {2} ]
comb6 = [ {}, {}, {1,2}]
comb7 = [ {}, {2}, {1} ]
comb8 = [ {2}, {1}, {} ]
comb9 = [ {2}, {}, {1} ]
Ideas are extremely welcome.
here is the solution: