How many ways can we distribute $r$ identical balls into $n$ distinct boxes with exactly $m$ boxes empty

we're looking for exactly $m$ boxes empty.

So after fixing empty boxes in $C(n,m)$ ways, we want to solve $x_1 + x_2 \ldots x_{n-m} = r$ where $x_i \geq 1 \; \forall 1\leq i \leq n-m$ which gives $C(r-1,n-m-1)$

So answer should be $C(n,m)*C(r-1,n-m-1)$

which doesn't agree with one of the answers on this post:

So which is the correct answer?

  • $\begingroup$ The question says that none of the boxes is to be empty, and has no mention of $m$. Where do you get, "We're looking for exactly $m$ empty boxes?" $\endgroup$
    – saulspatz
    Commented Nov 3, 2019 at 22:57
  • $\begingroup$ The post has identical balls and your has distinct and same problem with the boxes $\endgroup$ Commented Nov 3, 2019 at 22:58
  • $\begingroup$ Sorry, wrong title, it's been updated. check now. I mis-typed the title at first. $\endgroup$
    – chesslad
    Commented Nov 3, 2019 at 22:59
  • $\begingroup$ Yes, yours is correct. I have commented on the answer. $\endgroup$ Commented Nov 4, 2019 at 0:12

1 Answer 1


You are right.

After fixing $m$ empty boxes ($n\choose m$ ways), and one ball in each of the other $n-m$ boxes (one way), you have $r-(n-m)$ balls remaining to put freely into $n-m$ boxes, and the stars and bars formula gives you $${[r-(n-m)]+[n-m]-1\choose [n-m]-1}={r-1\choose n-m-1}\text{ ways}$$


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .