How to find the number of $k$-permutations of $n$ objects with $x$ types, and $r_1, r_2, r_3, \cdots , r_x$ = the number of each type of object? I asked this on Math Stackexchange, but didn't really receive an answer - so I figured this might be the right place.

How can I find the number of k-permutations of n objects, where there are x types of objects, and r1, r2, r3 ... rx give the number of each type of object?
Here is an example with $n = 20, k = 15, x = 4,$ $ r_1 = 4 \quad r_2 = 5 \quad r_3 = 8 \quad r_4 = 3$.

I have 20 letters from the alphabet. There are some duplicates - 4 of them are a, 5 of them are b, 8 of them are c, and 3 are d. How many unique 15-letter permutations can I make?

Furthermore, if there isn't a straightforward solution: how efficiently can this problem be solved?
 A: Here's a sketch of an idea. Consider first the problem of computing the number of permutations of $k$ elements given the number of elements $n_i$ in each class. This is easy: it works out to $$\frac{k!}{\Pi_i n_i !}$$
because in any fixed string, you can permute the elements in a class without changing the string. 
Now consider the problem of writing down the different partitions of $k$ into the sum of $x$ labelled numbers. Merely finding the sum itself  can be done by determining the coefficient of $y^k$ in the polynomial 
$$ \Pi_i \frac{y^{r_i+1}-1}{y-1}$$
But this is not enough, since you need to weight each such partition by a different number. However, we know that the contribution of $y^i$ must be $1/i!$, so the overall number we are looking for is $k!$ times the coefficient of $y^k$ in the polynomial 
$$ \Pi_i \sum_{j=0}^{r_i} \frac{y^j}{j!}$$
A: I match variables to the first letter of the mathematical object, so that your question is how to find $p$ permutations of $t$ things with $k$ kinds, where $n_1, n_2, n_3, \cdots , n_k$ = the number of each kind of thing.
To deduce the formula for all the unique permutations of length $l$ of $\{n_1,n_2,...,n_k\}$, we must find all combinations  $C=\{c_1,c_2,...,c_k\}$ where $0 \leq c_k \leq n_k$, such that
$
\sum_{i=1}^k c_i=l
$.
What we need, is actually the product of the factorials of the elements of that combination:
$
\color{limegreen}{\prod_{i=1}^k c_i!}
$
Presuppose that the number of combinations is J. Then to answer your question,  the number of permutations is
$$
= \sum_{j=1}^J \frac{l!}{\color{limegreen}{\prod_{i=1}^k c_i!}}
= \sum_{c_1+c_2+...+c_k=l} \binom{l}{c_1,c_2, \cdots ,c_n},
$$
as a  closed form expression with a Multinomial Coefficient. QED.
