How many ways to pick $X$ balls Suppose i have $3$ types of balls $A,B$ and $C$ and there are $n_a, n_b,$ and $n_c$ copies of these balls. Now i want to select $x$ balls from these $3$ types of balls $x < n_a + n_b + n_c$. Can anybody help me to arrive at the closed formula for this.
I thought, if I partition $x$ into $3$ partition it will do but in that case its quite possible that i can pick more ball of particular type than its actual count.
 A: What you are looking for is the coefficient of $k^x$ in $(1+k+k^2\dots k^{n_a})(1+k+k^2\dots k^{n_b})(1+k+k^2\dots k^{n_c})$
A: As Bananarama's answer says, it is:
\begin{align}
[z^n] (1 + z + \ldots + z^{n_a})& (1 + z + \ldots + z^{n_b}) (1 + z + \ldots + z^{n_c}) \\
  &= [z^n] 
       \frac{1 - z^{n_a + 1}}{1 - z} 
       \cdot \frac{1 - z^{n_b + 1}}{1 - z} 
       \cdot \frac{1 - z^{n_c + 1}}{1 - z} \\
  &= [z^n] \frac{(1 - z^{n_a + 1}) (1 - z^{n_b + 1}) (1 - z^{n_c + 1})}{(1 - z)^3} \\
\end{align}
Multiply out the denominator, then you can pick out the respective terms of
$$
(1 - z)^{-3} = \sum_{k \ge 0} (-1)^k \binom{-3}{k} z^k
          = \sum_{k \ge 0} \binom{k + 3 - 1}{3 - 1} z^k
$$
Finally note the binomial coefficients are just quadratic polynomials in $k$.
A: This problem can be easily solved with Principle of Inclusion Exclusion (PIE) and the Balls and Urns technique. The answer is:
$\dbinom{x+2}{2} - \dbinom{x-n_a+1}{2} - \dbinom{x-n_b+1}{2} - \dbinom{x-n_c+1}{2} + \dbinom{x-n_a-n_b}{2} + \dbinom{x-n_a-n_c}{2} + \dbinom{x-n_b-n_c}{2} - \dbinom{x-n_a-n_b-n_c-1}{2}$.
Hint: Each term corresponds to the number of non-negative integer solutions $(a,b,c)$ to $a+b+c = x$ with 0, 1, 2, or 3 of the following conditions enforced:
$a > n_a$
$b > n_b$
$c > n_c$
A: I am having the same question and looking for a solution which scales largely and it was not clear to me how the other answers here are closed or how I can implement them for arbitrarily large problems.
Here is a non-closed solution, just to document my own progress on this problem:

There are $\{b_1, b_2, \ldots, b_n\}$ copies of the balls.
We are selecting $x$ balls.
The trivial solution:
$$f(x, \{b_1\})=\begin{cases}1,&x<=b_1\\0,&x>b_1\end{cases}$$
The recursive part:
$$f(x, \{b_1, b_2, \ldots, b_n\}) = \sum_{i=0}^{b_1}f(x-i,\{b_2, \ldots, b_n\})$$
