# How many ways can we put balls in boxes? [duplicate]

Straight-forward: given $$x$$ identical balls and $$n$$ boxes, how many different ways can we place the balls into the boxes? A box can be empty.

example: x = 4, n = 3

|OOOO| - |    | - |    |
|OOO | - |O   | - |    |
|OOO | - |    | - | O  |
|OO  | - |OO  | - |    |
|OO  | - |O   | - |O   |
|OO  | - |    | - |OO  |
|O   | - |OOO | - |    |
|O   | - |OO  | - |O   |
|O   | - |O   | - |OO  |
|O   | - |    | - |OOO |
|    | - |OOOO| - |    |
|    | - |OOO | - |O   |
|    | - |OO  | - |OO  |
|    | - |O   | - |OOO |
|    | - |    | - |OOOO|

ANS = 15


In this case, seems like we have a sum $$(1+2+3+4+5)$$.

example: x = 3, n = 4

|OOO| - |   | - |   | - |   |
|OO | - |O  | - |   | - |   |
|OO | - |   | - |O  | - |   |
|OO | - |   | - |   | - |O  |
|O  | - |OO | - |   | - |   |
|O  | - |O  | - |O  | - |   |
|O  | - |O  | - |   | - |O  |
|O  | - |   | - |OO | - |   |
|O  | - |   | - |O  | - |O  |
|O  | - |   | - |   | - |OO |
|   | - |OOO| - |   | - |   |
|   | - |OO | - |O  | - |   |
|   | - |OO | - |   | - |O  |
|   | - |O  | - |OO | - |   |
|   | - |O  | - |O  | - |O  |
|   | - |O  | - |   | - |OO |
|   | - |   | - |OOO| - |   |
|   | - |   | - |OO | - |O  |
|   | - |   | - |O  | - |OO |
|   | - |   | - |   | - |OOO|

ANS = 20


In this case, seems like we have a sum $$(1+3+6+10)$$.

• This has been answered many times before on this site. Please do some research before asking questions. – K.defaoite Jun 22 '20 at 19:49
• Are balls identical or distinct? Are boxes identical or distinct? – UmbQbify Jun 22 '20 at 20:35
• The balls are identical. – Daniel Jun 22 '20 at 20:46
• Have you ever heard about stars and bars? – user Jun 22 '20 at 21:12

The way to place x balls in n boxes (where boxes can be empty) is:
$$\binom{x + n - 1}{n - 1}$$