Академический Документы
Профессиональный Документы
Культура Документы
Problem. Suppose we have n balls, and k boxes. How many dierent ways
are there of distributing the balls into the boxes? }
1 3 5 2 4 1 2 5 3 4
Notice, however, that if the balls were indistinguishable, then these distri-
butions would be identical: in both distributions, Box 1 gets three balls,
and Box 2 get two. Similarly, these two distributions are distinct:
1 3 5 2 4 2 4 1 3 5
We sometimes further divide the four variants of the balls and boxes
problem by saying that each box must contain at least one ball. In addition,
we might insist that each box must contain no more than one ball, but the
answers in this case tend not to be very interesting. Thus there are twelve
potential subproblems, so this classification of problems is sometimes called
the Twelvefold Way.
25
MATH 261 Enumeration 4. Balls and boxes
| || |
In this case each of the symbols represents a ball, and the | symbols are
separators between consecutive boxes. So the string above represents the
distribution where Box 1 gets three balls, Box 2 gets one, Box 3 gets none,
Box 4 gets two, and Box 5 gets one.
Now we just need to count the number of such strings. Each string
contains n + k 1 characters (n to represent the n balls, and k 1 to
represent the separators between the k boxes). Once we have decided which
of the n + k 1 slots contains a character, then the string is completely
determined. Therefore the number of strings is equal to the number of ways
we can choose n slots from n + k 1 possibilities. This is just n+kn 1 .
x1 + + xk = n,
Example. We have access to red, blue, and green marbles. We would like
to fill a jar with 50 marbles. How many dierent ways can we do this?
The answer is going to be the number of solutions to the equation
26
MATH 261 Enumeration 4. Balls and boxes
where xred , for example, is the number of red marbles in the jar. (So xred
must be a non-negative integer.) Therefore the answer is 50+3
50
1
= 1326.}
Next, lets look at the case that every box must contain at least one ball.
Example. We want to fill a jar with 50 marbles, and the marbles are either
red, green, or blue. How many ways are there to fill the jar if we insist that
we take at least one of each colour? The answer is equal to the number of
solutions to the equation
27
MATH 261 Enumeration 4. Balls and boxes
Proof. For each ball we have k options when deciding which box to put it
in. Thus we have to make n choices, and for each choice we have k options.
The Multiplication Principle tells us that the total number of options is k n .
These options are all distinct, as the balls and boxes are distinguishable.
Example. How many functions are there from {1, . . . , 10} to {1, . . . , 8}?
We think of choosing a function as putting balls labeled 1 to 10 into
boxes labeled 1 to 8. Putting Ball 1 into Box 4, for example, means that
we have chosen f (1) to be 4. Therefore there are 810 = 1073741824 possible
functions. }
What if we insist that each tutor must be assigned at least one student?
The next result result shows us how to find the answer.
Proposition 4.4. Suppose that we have n distinguishable balls, and k dis-
tinguishable boxes. The number of dierent ways of distributing the balls
into the boxes so that each box contains at least one ball is
n n k n s k
k k(k 1) + (k 2) + + ( 1) (k s)n
k 2 k s
k 1
X
k 1 s k
+ + ( 1) k = ( 1) (k s)n .
k s
s=0
28
MATH 261 Enumeration 4. Balls and boxes
29
MATH 261 Enumeration 4. Balls and boxes
30
MATH 261 Enumeration 4. Balls and boxes
Proposition 4.8. Suppose that n > 1 is an integer, and 1 < k < n. Then
Proof. Consider the partitions of {1, . . . , n} into k parts. There are two
types of such partitions: those where n is contained in a block by itself,
and those where it is not. If we have a partition of the first type, we can
construct a partition of {1, . . . , n 1} into k 1 parts by simply deleting n.
This is a one-to-one correspondence between partitions of the first type, and
partitions of {1, . . . , n 1} into k 1 parts. Thus the number of partitions
of the first type is S(n 1, k 1).
Now we consider partitions of the second type, where n is contained
in a block with other element(s). By deleting n, we produce a partition
of {1, . . . , n 1} into k parts. But there are k partitions that would have
produced the same partition of {1, . . . , n 1} after deleting n, because n
might have been contained in any of the k blocks. Therefore the number of
partitions of the second type is kS(n 1, k). The result follows.
1
1 1
1 3 1
1 7 6 1
1 15 25 10 1
1 31 90 65 15 1
1 63 301 350 140 21 1
31
MATH 261 Enumeration 4. Balls and boxes
32
MATH 261 Enumeration 4. Balls and boxes
Now we can solve the more general problem, where boxes are allowed to
be empty.
Proof. If no boxes are empty, then there are S(n, k) distributions, by Propo-
sition 4.10. If exactly one box is empty, then k 1 boxes are non-empty, so
there are S(n, k 1) such solutions. We continue in this way, until we see
that there are S(n, 1) = 1 distributions with k 1 boxes empty, and 1 box
not empty. Adding these numbers together gives us the result.
5 + 1 + 1, 4 + 2 + 1, 3 + 3 + 1, and 3 + 2 + 2. }
33
MATH 261 Enumeration 4. Balls and boxes
Proposition 4.14. Suppose that n > 1 is an integer, and 1 < k < n. Then
Entry number k in row number n is p(n, k). The rows of this triangle
are sequence A008284.
If n is a positive integer, then we define p(n) to be
n
X
p(n, k).
k=1
34
MATH 261 Enumeration 4. Balls and boxes
35
MATH 261 Enumeration 4. Balls and boxes
Proof. We sum over the number of boxes that are non-empty, and apply
Proposition 4.16.
We can now state a solution to all the variants of the balls in boxes
problem. Each cell in Table 1 contains a reference to the corresponding
result in these notes. Moreover, we have also collected all the solutions
to the subproblem of the balls and boxes problem where all the boxes are
required to contain at least one ball. The solutions to that subproblem are
noted in Table 2.
Balls Balls
distinguishable indistinguishable
Bins n+k 1
kn (4.3) n (4.1)
distinguishable
Bins Pk Pk
indistinguishable i=1 S(n, i) (4.11) i=1 p(n, i) (4.17)
Balls Balls
distinguishable indistinguishable
Bins n 1
k!S(n, k) (4.4),(4.10) k 1 (4.2)
distinguishable
Bins
S(n, k) (4.10) p(n, k) (4.16)
indistinguishable
36