Exam question: Let $D(d_{1},d_{2},...,d_{k})$ denote the number of derangements of a multiset where there are $d_{i}$ copies of elements of the $i$-th kind, for $i=1,...,k$. This means the arrangements of elements of this multiset in a sequence such that in the first $d_{1}$ positions there is no element of the first kind, in the next $d_{2}$ positions there is no element of the second kind, and so on. For example: $D(1,2)=0, D(2,2)=1, D(1,1,2)=2$. The only derangements of the multiset $\{a,b,c,c\}$ are $\langle c,c,a,b \rangle$ and $\langle c,c,b,a \rangle$.
Find $D(2,2,2,3)$. The WolframAlpha website might be useful for calculations.
Initially, I was thinking about the principle of inclusion and exclusion:
$ \frac{9!}{2! \cdot 2! \cdot 2! \cdot 3!} - 6 \binom{8}{1} \binom{7}{2} \binom{5}{2} - 3 \binom{8}{2} \binom{6}{2} \binom{4}{2} + \left( 3 \cdot 2 \cdot 2 \cdot \binom{6}{1} \cdot \binom{6}{1} \cdot \binom{5}{2} + 3 \binom{7}{2} \binom{5}{2} \right) + \left( 3 \cdot 3 \cdot 2 \cdot \binom{7}{1} \binom{6}{2} \binom{4}{2} + 3 \cdot \binom{7}{1} \binom{6}{2} \binom{4}{2} \right)-... $
Where in the first parenthesis I subtract situations when one of the letters a, b, c is in the wrong position, in the second parenthesis when d is in the wrong position, in the third parenthesis pairs but without the letter d and dividing into situations when the pair consists of two identical letters (both letters a, a are in the wrong positions) or two different ones (e.g., a, b). The fourth is the same as the third but is a case for pairs with the letter d. The problem is that there are still seven cases to consider left, and each subsequent one is worse.
Brute force approach gives me $D(2,2,2,3)= 564$.
I have found similar questions Derangement formula for multisets, Derangements of a multiset with "don't cares"? and I tried using the given formula but it doesn't seem to work: WolframAplha.
How can one count these combinations?
-$D(2,2)$ for 'aabb': $1$ -$D(2,2,2)$ for 'aabbcc': $10$ -$D(2,2,2,2)$ for 'aabbccdd': $297$ -$D(2,2,2,3)$ for 'aabbccddd': $564$ -$D(1,1,1,1)$ for 'abcd': $9$ -$D(3,3,3,3)$ for 'aaabbbcccddd': $13833$ -$D(2,2,2,2,2,2)$ for 'aabbccddee': $13756$
– Michał Aug 18 '23 at 16:51