Choosing with conditional replacement To phrase my problem within a standard combinatorial metaphor:
Say you have a bag with $n$ distinct balls in it. You repeat the following process $k$ times. Choose a ball from the bag at random, and then, if you have chosen this ball $<l$ times, you put it back in the bag, otherwise you discard it.
How many different ways are there of doing this?
I tried to approach the problem via simply counting choices with (unconditional) replacement, then subtracting the cases where the same ball was chosen more than $l$ times, but I can't quite get it to work. I'm struggling to come up with a different approach.
 A: You want to count the number of sequences of length $k$ where each entry is an integer between $1$ and $n$, and each integer appears at most $l$ times. For example, when $n=2,l=2$ and $k=3$, the valid sequences are $AAB,ABA,BAA,ABB,BAB,BBA$. 
There is no closed form solution, but it can be solved using exponential generating functions, which leads to a nice computational solution. Specifically, let
$$
E_{l}(x)=\sum_{k=0}^{l}\frac{x^k}{k!}
$$
be the $l^{th}$ partial sum of the exponential series. Then the number of sequences is equal to $k!$ times the coefficient of $x^k$ in $(E_{l}(x))^n$. 
For example, suppose $n=3$ and $l=2$. Then
$$
(E_{2}(x))^3=(1+x/1!+x^2/2!)^3=1+3x+\tfrac92 x^2 + 4x^3+\tfrac94x^4+\tfrac34x^5+\tfrac{1}8
x^6$$
Taking this list of coefficients, and multiplying the $k^{th}$ coefficient by $k!$, gives
$$
\begin{array} {|r|c|c|c|c|c|c|c|}
\hline
k & 0 & 1 & 2&3&4&5&6\\\hline
k!\cdot \text{coefficient of $x^k$}&1&3&9&24&54&90&90\\\hline
\end{array}
$$
You can verify that for each $k$, the above table gives the number of sequences of $k$ balls from $3$ types each appearing at most twice.
Added later: It is obviously still very tedious to perform these polynomial multiplications by hand, but they can be done very quickly on a  computer algebra system. Here is how you do it in Mathematica:
n = 10; 
l = 2; 
k = 4;
k! * Coefficient[ Sum[x^i/i!, {i,0,l}]^n, x^k] 

