# How many distinct n-letter “words” can be formed from a set of k letters where some of the letters are repeated?

How many distinct n-letter "words" can be formed from a set of k letters where some of the letters are repeated?

Examples:

__

How many 6-letter words can be formed from the letters: ABBCCC?

This is elementary. There are 6! arrangements counting repeats. Then we just divide by 2!3! to account for the repeats caused by the 2!3! identical arrangements of the Bs and Cs

How many 5-letter words can be formed from the letters: ABBCCC?

Excluding A we have $\frac{5!}{2!3!}$

Excluding either B $\frac{5!}{3!}$

Excluding any of the Cs $\frac{5!}{2!2!}$

Then take the sum.

How many 4-letter words can be formed from the letters: ABBCCC?

At this point I find it difficult to procede without far too many cases.

Is there a general approach?

-
Interesting question, perhaps difficult to give a nice answer to. In the particular instance, we remove AB or AC or BB or CC or BC, so the number of cases is manageable. –  André Nicolas Nov 16 '12 at 22:11
There's a nice exponential generating function for this problem. See this question. –  Jair Taylor Nov 17 '12 at 20:35
Thank you Jair! –  a little don Nov 29 '12 at 23:42

Let's say you want the word of letters to be $M$-long, with $N$ choices for letters in each space on the word. Then draw something like this:

to enumerate all possible words. In the picture $M=3$ and $N=2$. Let's say you have a deficit in $A$s of magnitude $D_A$ from being able to make a full, $M$-long word of $A$s.

First, assuming none of the deficits overlap (that is, there are no words that violate 2 or more restrictions in the number of letters), find the number of nodes that are less than or equal to $M-D_A$ away from $(A,A,...A)$. This turns out to be $\sum_{k=0}^{k=M-D_A}\binom{M}{k}{(N-1)}^{M-k}$.

For the proof of this, think of a 3-letter word with choices of letter $A$, $B$ or $C$. There are $\binom{3}{0}2^0$ ways of making words with 3 $A$s, $\binom{3}{1}2^1$ ways of making a word with 2 $A$s, etc.

So evidently you need to subtract each sum taking into account the restrictions of each letter from the total number of unrestricted words.

However, it's much more complicated when the sum of two deficits is more than $M$ so that because of the overlap the subtraction will have been too great. Basically the $(N-1)$ in the sum will be some lower number for higher values of $k$ when other letter's restrictions are overstepped, but I can't see a nice formula for it for a given $D_B, D_C...$.

-
$\frac{_nP_r}{n_1!n_2!...n_k!}$.