6

I would like to know how many $22$ letter words can be made that have exactly $7$ A's, $6$ B's , $5$ C's and $4$ D's and have no consecutive letters the same.

This problem is clearly equivalent to finding the number of ways to partition $[22]$ into $4$ sets of sizes $7,6,5,4$ such that no set contains consecutive integers, or to the number of ways of coloring $P_{22}$ properly using $4$ identical colors, with multiplicities $7,6,5$ and $4$

I have been having a lot of trouble with this question. It is a rather well known result that the number of ways to color any tree with $n$ vertices properly, using $k$ colors is $n-1\brace k-1$. But when we add restrictions to the number of vertices of each color it seems to be harder.

Inclusion-Exclusion seems to be useless also.


Other good answers to this problem can be found here and here

Asinomás
  • 105,651
  • Are you interested in this specfic problem, or rather in a general solution? – ajotatxe Aug 11 '15 at 11:28
  • Are you interested in the most efficient algorithm or the most elegant mathematical representation? – user21820 Aug 11 '15 at 11:53
  • @user21820 I am interested in both. – Asinomás Aug 11 '15 at 11:59
  • @ajotatxe I am interested in both, a solution (not answer) of the specific problem would be very much appreciated. – Asinomás Aug 11 '15 at 11:59
  • I'm afraid I can only give you a partially efficient algorithm and no elegant mathematical representation. – user21820 Aug 11 '15 at 12:00
  • That would be great, could it come with a c++ code? – Asinomás Aug 11 '15 at 12:01
  • Haha no I'm too lazy to code it.. but it's basically just converting the problem into a recurrence and implementing top-down recursion with memoization and trimming impossible subtrees.. do you know how to do that? – user21820 Aug 11 '15 at 12:02
  • sorry, the only term I know from your last comment is recursion. – Asinomás Aug 11 '15 at 12:05
  • Okay then I'll outline the method in an answer. – user21820 Aug 11 '15 at 12:11
  • 3
    Once again, I point to Jair Taylor's wonderful integral solution based on algebraic combinatorics. Applied to this problem, it gives the exact answer 460016238.

    http://math.stackexchange.com/questions/129451/find-the-number-of-arrangements-of-k-mbox-1s-k-mbox-2s-cdots/129802#129802

    –  Aug 11 '15 at 13:26
  • Thank you Byron, that works. Although I'm not sure if I should vote to close as duplicate as the question in the link is slightly less general. – Asinomás Aug 11 '15 at 13:28
  • @dREaM I wouldn't close your question. But Jair's answer is completely general; it covers much more than the asked question. –  Aug 11 '15 at 13:30
  • @ByronSchmuland: I don't understand why you were asked to repost this as a comment -- it seems like a great answer to me. – joriki Aug 11 '15 at 14:32
  • @joriki I don't understand either. I'm just happy that the OP has linked to Jair's answer. –  Aug 11 '15 at 14:53

2 Answers2

1

We fill up the positions from left to right. At each step all that matters is how many of each letter we have used up and what is the last letter we used, since it must not be the same as the next. So we can represent all this information as a tuple $(a,b,c,d,x)$ where $a,b,c,d$ are the number of occurrences of respective letters and $x$ is the last letter, say $1,2,3,4$ for 'A','B','C','D' respectively. Naturally let $f(a,b,c,d,x)$ be the number of ways to get to the state $(a,b,c,d,x)$. Clearly then we have the recurrence relation $f(a,b,c,d,1) = \sum_{x\in\{2,3,4\}} f(a-1,b,c,d,x)$. Likewise we have $f(a,b,c,d,2) = \sum_{x\in\{1,3,4\}} f(a,b-1,c,d,x)$, and so on. We can initialize $f(1,0,0,0,1) = 1$ and $f(0,1,0,0,2) = 1$ and so on. This defines a simple recursion to find the answer because we want $\sum_{x\in\{1,2,3,4\}} f(7,6,5,4,x)$.

Of course we must use memoization, which just means storing all previously computed values of $f(a,b,c,d,x)$ so that we do not do duplicate work. This ensures that the recursion goes through each state at most once. Since the total number of states is less than $8^4 \times 4$, this would finish fast. Also, you can prune off some states without even searching them. For example, $f(1,7,3,1,2) = 0$ because there are too many 'B's. This pruning will help decrease the time taken significantly, but it would still be exponential in word length.

user21820
  • 57,693
  • 9
  • 98
  • 256
1

I do not know whether you still interested in a solution or not , but i wanted to write an answer when i saw it.

To solve this messy process , i will use analytic combinatorics techniques. In analytic combinatorics , we call such arrangements as Smirnov or Carlitz words.I am putting a link for you link of the suggested book You can find detaily explanation here about my method , but i will not get in explanation . When you look at the related pages in book , you will see detailed info.

A generating function for the number of Smirnov words over an n-ary alphabet is given by $$\begin{align*} \left(1-\frac{nz}{1+z}\right)^{-1} \end{align*}$$

Here we consider an alphabet $\mathcal{K}=\{A,B,C,D\}$ with $n=4$ letters. Using $[z^k]$ to denote the coefficient of $z^k$ of a series we calculate

\begin{align*} &\color{green}{[A^7B^6C^5D^4]\left(1-\sum_{a\in\mathcal{V}}\frac{a}{1+a}\right)^{-1}}\\ &\qquad=[A^7B^6C^5D^4]\sum_{j=0}^{\infty}\left(\sum_{a\in\mathcal{V}}\frac{a}{1+a}\right)^j\\ &\qquad=[A^7B^6C^5D^4]\sum_{j=4}^{22}\left(\sum_{a\in\mathcal{V}}\frac{a}{1+a}\right)^j\\ &\qquad=[A^7B^6C^5D^4]\sum_{j=4}^{22}\left((A-A^2 +A^3 -A^4 +A^5-A^6 +A^7 )+\left(B-B^2 +B^3 -B^4 +B^5 -B^6\right)\right.\\ &\qquad\qquad\qquad\qquad\qquad\qquad\left.+(C-C^2 +C^3-C^4 +C^5 )+(D-D^2 +D^3 -D^4)\right)^j\\ &\qquad\\ &\,\, \end{align*}

I think you can calculate the coefficients of $[A^7B^6C^5D^4]$ in the exapnsion of $[A^7B^6C^5D^4]\sum_{j=4}^{22}((A-A^2 +A^3 -A^4 +A^5-A^6 +A^7 )+(B-B^2 +B^3 -B^4 +B^5 -B^6) +(C-C^2 +C^3-C^4 +C^5 )+(D-D^2 +D^3 -D^4))^j$ using computer program. I am putting a link of a similar question Link of similar question