Counting Solutions with the Principle of
Inclusion–Exclusion
Problem 3 Chapter 8.6
Find the number of solutions in nonnegative integers to
x1 + x2 + x3 = 13
subject to the extra restriction that each xi < 6 (i.e. 0 ≤ xi ≤ 5).
Easy step-by-step solution
We will use stars-and-bars together with the Principle of Inclusion–Exclusion (PIE). The
idea:
1. Count all nonnegative solutions without the upper bounds.
2. Subtract solutions where any variable is too large (≥ 6).
3. Add back solutions where two variables are too large (because they were subtracted
twice).
4. Subtract solutions where three variables are too large (if any).
1. Total nonnegative solutions. By stars-and-bars, the number of solutions to x1 +
x2 + x3 = 13 with xi ≥ 0 is
13 + 3 − 1
15
=
= 105.
3−1
2
(Think: place 13 identical stars into 3 boxes; we need 2 dividers, so choose 2 divider positions
out of 15.)
1
2. Count solutions where a particular variable is at least 6. Let Ai be the set of
solutions with xi ≥ 6. To count |A1 | do the substitution x′1 = x1 − 6 ≥ 0. Then
x′1 + x2 + x3 = 7.
Using stars-and-bars again gives
7+3−1
9
|A1 | =
=
= 36.
3−1
2
By symmetry, each |Ai | equals 36, so the sum of single variable counts is
3
X
|Ai | = 3 · 36 = 108.
i=1
3. Count solutions where two variables are at least 6. For A1 ∩A2 set x′1 = x1 −6 ≥ 0
and x′2 = x2 − 6 ≥ 0. Then
x′1 + x′2 + x3 = 1.
The number of nonnegative solutions is
1+3−1
3
=
= 3.
3−1
2
There are 3 unordered pairs of indices, so the total for pairs is
X
|Ai ∩ Aj | = 3 · 3 = 9.
i<j
4. Count solutions where all three variables are at least 6. If x1 , x2 , x3 ≥ 6 then
subtracting 6 from each yields
x′1 + x′2 + x′3 = 13 − 18 = −5,
which is impossible. So
|A1 ∩ A2 ∩ A3 | = 0.
5. Apply PIE. By inclusion–exclusion the number of solutions with 0 ≤ xi ≤ 5 is
X
X
#valid = total −
|Ai | +
|Ai ∩ Aj | − |A1 ∩ A2 ∩ A3 |
i
i<j
= 105 − 108 + 9 − 0 = 6.
So there are 6 solutions.
2