Find valid assignments of integers in arrays (permutations with given order)
- by evident
Hi everybody!
I am having a general problem finding a good algorithm for generating each possible assignment for some integers in different arrays.
Lets say I have n arrays and m numbers (I can have more arrays than numbers, more numbers than arrays or as much arrays as numbers).
As an example I have the numbers 1,2,3 and three arrays:
{ }, { }, { }
Now I would like to find each of these solutions:
{1,2,3}, { }, { }
{ }, {1,2,3}, { }
{ }, { }, {1,2,3}
{1,2}, {3}, { }
{1,2}, { }, {3}
{ }, {1,2}, {3}
{1}, {2,3}, { }
{1}, { }, {2,3}
{ }, {1}, {2,3}
{1}, {2}, {3}
So basically I would like to find each possible combination to assign the numbers to the different arrays with keeping the order. So as in the example the 1 always needs to come before the others and so on...
I want to write an algorithm in C++/Qt to find all these valid combinations.
Does anybody have an approach for me on how to handle this problem? How would I generate these permutations?