I'm trying to come up with a recursive algorithm to generate all possible child - parent assignment possibilities given complete randomness.
For example, say I have 3 children and 2 parents, all children will be randomly assigned to each parent with the following possible outcomes
Parent 1 Parent 2
0 Children 3 Children
1 Children 2 Children
2 Children 1 Children
3 Children 0 Children
I've been trying to wrap my head around a way to do this recursively supplying the number of children and number of parents along with other variables for keeping track of the current state but have been unable to find anything that works. It needs to work for any given number of parents and children.
Does anyone have any ideas? I'm coding in Java although its not so much the code but the algorithm I need help with.
Aucun commentaire:
Enregistrer un commentaire