How many positive integer solutions are there to the equality $x_1+x_2+...+x_r= n$?

The original problem is there are $r$ identical boxes and $n$ identical balls. Every box is nonempty. Then how many ways of putting balls in boxes?

It is equivalent to the problem of finding integer solutions for the equality: $$x_1+x_2+...+x_r= n$$ and $x_i>0$ for all $1\leq i\leq r$.

Editted by @Sil: Replaced with equality to avoid confusion that this question deals with $x_1+x_2+\dots+x_r\leq n$, which it does not!


Solution 1:

If $r>n$ this cannot be done.

Otherwise, write $n = 1+ 1 +1+1+ \dots + 1+1+1$ and choose $r-1$ 'plus signs' in this string. In this way you are writing $n$ as a sum $(1+ \dots +1) + (1+\dots +1) + \dots + (1+\dots +1) = x_1 + x_2 + \dots + x_r$.

This means that you have to choose $r-1$ elements in a set of $n-1$ elements, so the answer is $\binom{n-1}{r-1}$.