Put B balls in C containers. How many combinations have box(es) with exactly 2 balls? Assume that we have B balls (all the same) and C numbered containers (distinguishable). We want to calculate how many of the total combinations contain exactly 1 container with 2 balls, exactly 2 containers with 2 balls, etc.
The way I see it, first step is to calculate the different ways that we can distribute the B balls in C containers, assuming that each container can have any number of balls, including zero. According to the Stars and bars paradigm, assuming that I am not making a mistake, this should be:
$\dbinom{B+C-1}{C-1}$
Second step is to calculate how many of those combinations have:


*

*exactly 1 container with 2 balls

*exactly 2 containers with 2 balls

*exactly 3 containers with 2 balls

*etc


which I have no idea how to do and any leads or suggestions are greatly appreciated!
 A: Hint: Try to use the generalized inclusion exclusion principle. http://en.wikipedia.org/wiki/Inclusion%E2%80%93exclusion_principle#A_generalization
A: Assume that there have to be exactly $c$ containers containing $2$ balls. Choose these $c$ containers in one of ${C\choose c}$ ways, and put two balls in each of them. The numbers
$$C':=C-c, \quad B':=B-2c$$
remain fixed in the sequel.
There will be $m$ containers with $\geq3$ balls, where $m$ has to satisfy
$$0\leq m\leq M:=\min\left\{\biggl\lfloor{B'\over3}\biggr\rfloor, C'\right\}\ .$$
Choose these $m$ containers in one of ${C'\choose m}$ ways, and put three balls in each of them. Now there are $C'-m\geq0$ containers still empty, and there are $B'-3m\geq0$ balls left over.
We can decide to put a single ball into $k$ of the empty containers, where $k$ has to satisfy
$$0\leq k\leq k_m:=\min\{C'-m,B'-3m\}\ .$$ This can be done in ${C'-m\choose k}$ ways.
Now there are $B'-3m-k\geq0$ balls left, which can be freely distributed in the $m$ containers already holding $3$ balls. When $m\geq1$ this can be done in
$${B'-3m-k+(m-1)\choose m-1}={B'-2m-k-1\choose m-1}$$
ways; the case $m=0$ is special, see below.
Putting it all together the requested number $N$ comes to
$$N={C\choose c}\cdot\left({C'\choose B'}+\sum_{m=1}^M {C'\choose m}\sum_{k=0}^{k_m}      {C'-m\choose k}{B'-2m-k-1\choose m-1}\right)\ .$$
I don't think that the double sum can be simplified.
