# Need help in a counting problem

$N$ boxes are lined up in a sequence. You have $A$ red balls and $B$ blue balls. The red balls (and the blue ones) are exactly the same. You can place the balls in the boxes. It is allowed to put in a box, balls of the two kinds, or only from one kind. You can also leave some of the boxes empty. It's not necessary to place all the balls in the boxes. Count the number of different ways to place the balls in the boxes in the described way.

If there was only $1$ ball the answer would have been $\binom {N+A-1} {N-1}$. But I dont know how to solve it for $2$ balls.

• Not all balls need to be distributed. This is equivalent to having an additional box. So the number of ways with only $A$ balls of one type is $\binom{N+A}{N}$, and for your problem the number of ways is $\binom{N+A}{N}\binom{N+B}{B}$. And the idea generalizes. – André Nicolas Mar 1 '15 at 15:03

By Fundamental Principle of Counting, you just have to multiply them to acquire the combinations of simultaneous occurrence. So, your answer simply would be $$\binom{N+A-1}{N-1}\times\binom{N+B-1}{N-1}$$
• $A,B>N$ should be true for this formula to be correct. – AvZ Mar 1 '15 at 13:18
• For example, distributing the a single ball to $2$ boxes, there are $3$ ways to do so (Put it in box $1$ or $2$, or don't put it in any box). But the formula will give ${2\choose 1}=2$ which is incorrect. – AvZ Mar 1 '15 at 13:24
• @AvZ: Not all the balls need to be distributed. It is useful to imagine there are $N+1$ boxes, the last one being for items not distributed. Then Stars and Bars and multiplication give $\binom{N+A}{N}\binom{N+B}{B}$. – André Nicolas Mar 1 '15 at 14:45