I have a set of elements, for example: {1,1,1,2,2,3,3,3} and a bounding set of sets, for example {{3}, {1,2}, {1,2,3}, {1,2,3}, {1,2,3}, {1,2,3}, {2,3}, {2,3}. I am looking for permutations of elements, but the first element should be 3, and the second should be 1 or 2, etc.
One such permutation that fits: {3,1,1,1,2,2,3}
Is there an algorithm to count all permutations for this problem at all? Is there a name for this type of problem?
To illustrate, I know how to solve this problem for certain types of "bounding sets". Elementset: {1,1,2,2,3}, Constraints {{1,2}, {1,2,3}, {1,2,3}, {1,2}, {1,2} }. This is 2! / (2-1)! / 1! * 4! / 2! / 2 !. Effectively rearranging the first three, since they are the most restrictive, and then rearranging the rest of the objects where there is space.
Also ... polynomial time. Is it possible?
UPDATE: This is discussed further in the links below. The above problem is called "counting perfect matches", and each permutation restriction above is represented as {0,1} on the matrix of slots for residents.