Skip to content

Combinations with Repetition and Integral Equations

In Section 06, we counted ordered arrangements when repetition is allowed any number of times (\(n^k\)). Now we ask the unordered counterpart: in how many ways can we select \(n\) objects from \(k\) distinct types when each type is available in unlimited supply and only the quantity of each type matters?

This single idea—known as the Binary String or Stars and Bars method—translates directly into counting integer solutions of linear equations, unlocking a vast class of combinatorial problems.


Non-Negative Integer Solutions: The Fruit Shop and Binary Strings

Let \(A = \{\infty \cdot a_1,\; \infty \cdot a_2,\; \dots,\; \infty \cdot a_k\}\) be a multiset of \(k\) distinct types of objects in unlimited supply, and suppose we wish to select \(n\) objects from \(A\) (without regard to order).

To see what "infinite supply" really means in practice, picture a fruit shop selling mangoes, oranges, and avocados (\(k = 3\) types). Suppose the shop stocks \(100\) mangoes, \(25\) oranges, and \(50\) avocados, and you want to buy \(n = 20\) fruits in total. Even if you decide to buy all \(20\) oranges, the shop has \(25\) in stock and can easily fulfill your order. Whenever the stock of every type is at least \(n\), "sufficient supply" behaves identically to "infinite supply"!

Because the order in which fruits go into your shopping bag does not matter, a purchase is completely determined by the three non-negative integers:

  • \(x_1 =\) number of mangoes bought,
  • \(x_2 =\) number of oranges bought,
  • \(x_3 =\) number of avocados bought,

satisfying the linear equation:

\[x_1 + x_2 + x_3 = 20, \qquad x_1 \ge 0,\; x_2 \ge 0,\; x_3 \ge 0\]

(Notice that \(x_i \le 20\) holds automatically since all variables are non-negative and sum to \(20\); we do not need to write it separately.)

In general, selecting \(n\) objects from \(k\) types in unlimited supply is in exact bijection with finding all non-negative integer solutions \((x_1, x_2, \dots, x_k)\) to:

\[x_1 + x_2 + \dots + x_k = n, \qquad x_i \ge 0 \quad (1 \le i \le k)\]

The Binary String Bijection

How do we count all non-negative integer solutions of \(x_1 + x_2 + x_3 = 20\) without listing them? Construct a bijection with binary strings containing \(20\) zeros (0) and \(2\) ones (1)!

Look at how any string of twenty 0s and two 1s encodes a unique fruit purchase:

  • \(x_1 =\) number of 0s to the left of the first 1,
  • \(x_2 =\) number of 0s between the two 1s,
  • \(x_3 =\) number of 0s to the right of the second 1.

The two 1s act as dividers slicing the twenty 0s into three parts. Check the boundary cases carefully:

  • If the first 1 sits at the very left end, there are no 0s before it, so \(x_1 = 0\).
  • If the two 1s sit right next to each other, there are no 0s between them, so \(x_2 = 0\).
  • If the second 1 sits at the very right end, there are no 0s after it, so \(x_3 = 0\).

Bijection Between Binary Strings and Non-Negative Solutions of x1 + x2 + x3 = 20

Every binary string of \(20\) zeros and \(2\) ones corresponds to one and only one non-negative solution of \(x_1 + x_2 + x_3 = 20\), and every solution corresponds to one and only one binary string. By the Bijection Principle and the Multiset Permutation Formula (Section 06), the total number of ways to buy \(20\) fruits is the number of distinct arrangements of twenty 0s and two 1s:

\[\frac{(20 + 2)!}{20!\,2!} = \frac{22!}{20!\,2!} = \frac{22 \times 21}{2} = 231\]

The General Formula

In general, for \(x_1 + x_2 + \dots + x_k = n\) (\(x_i \ge 0\)), we use a binary string of \(n\) zeros and \(k - 1\) ones (\(k - 1\) dividers partition a row of zeros into \(k\) regions). The total string length is \(n + k - 1\).

Theorem (Combinations with Unlimited Repetition): The number of unordered selections of \(n\) objects from \(k\) distinct types in unlimited supply—equivalently, the number of non-negative integer solutions to \(x_1 + x_2 + \dots + x_k = n\)—is:

\[\frac{(n + k - 1)!}{n!\,(k - 1)!} = \binom{n + k - 1}{k - 1} = \binom{n + k - 1}{n}\]

Example 1: How many distinct terms appear in the expansion of \((a + b + c + d)^{10}\) after combining like terms?

Solution: Every term in the expansion has the form \(a^{x_1} b^{x_2} c^{x_3} d^{x_4}\) where \(x_1 + x_2 + x_3 + x_4 = 10\) and \(x_i \ge 0\). Here \(n = 10\) and \(k = 4\), so the number of distinct terms is:

\[\binom{10 + 4 - 1}{4 - 1} = \binom{13}{3} = \frac{13 \times 12 \times 11}{6} = 286\]

Positive Integer Solutions (At Least One of Each Type)

Return to the fruit shop: suppose you still want to buy \(20\) fruits, but now you must buy at least one mango, at least one orange, and at least one avocado. Our equation becomes:

\[x_1 + x_2 + x_3 = 20, \qquad x_1 \ge 1,\; x_2 \ge 1,\; x_3 \ge 1\]

How do we reduce this to the standard form we already solved? Make a change of variables! Define:

\[x_1 = y_1 + 1, \qquad x_2 = y_2 + 1, \qquad x_3 = y_3 + 1\]

Why does this substitution work so cleanly? Because \(x_1 \ge 1 \iff y_1 + 1 \ge 1 \iff y_1 \ge 0\) (and similarly \(y_2 \ge 0, y_3 \ge 0\)). Substituting into the equation gives:

\[(y_1 + 1) + (y_2 + 1) + (y_3 + 1) = 20 \implies y_1 + y_2 + y_3 = 17 \qquad (y_1, y_2, y_3 \ge 0)\]

(Intuitively, you put \(1\) mango, \(1\) orange, and \(1\) avocado into your basket first, and now you freely choose the remaining \(17\) fruits with no restrictions!) Applying our standard formula with \(n = 17\) and \(k = 3\):

\[\binom{17 + 3 - 1}{3 - 1} = \binom{19}{2} = \frac{19 \times 18}{2} = 171\]

Theorem (Positive Integer Solutions): For \(n \ge k\), the number of positive integer solutions to \(x_1 + x_2 + \dots + x_k = n\) (\(x_i \ge 1\) for all \(1 \le i \le k\)) is:

\[\binom{n - 1}{k - 1}\]

We prove this in two illuminating ways—both ideas are worth mastering.

Proof 1 (Variable Shift): Substitute \(x_i = y_i + 1\) for each \(i = 1, 2, \dots, k\). Then each \(y_i \ge 0\) and \(y_1 + y_2 + \dots + y_k = n - k\). By the non-negative solution formula, the number of solutions is:

\[\binom{(n - k) + k - 1}{k - 1} = \binom{n - 1}{k - 1} \qquad \blacksquare\]

Proof 2 (Gap Method on Binary Strings): Consider again a binary string of \(n\) zeros and \(k - 1\) ones. Because every variable must satisfy \(x_i \ge 1\), no two 1s may be adjacent (which would force a middle variable to be \(0\)), and no 1 may sit at the leftmost or rightmost end (which would force \(x_1 = 0\) or \(x_k = 0\)).

Lay out the \(n\) zeros in a line. Between consecutive zeros there are exactly \(n - 1\) interior gaps. Placing the \(k - 1\) identical ones into \(k - 1\) of these \(n - 1\) interior gaps automatically guarantees at least one zero in every region! Choosing \(k - 1\) gaps out of \(n - 1\) can be done in \(\binom{n - 1}{k - 1}\) ways. \(\blacksquare\)

Positive Integer Solutions via Choosing Interior Gaps Between Zeros


General Lower Bounds and Linear Inequalities

The variable-shift method handles any lower bounds \(x_i \ge a_i\)—even negative integers!

Theorem (Arbitrary Lower Bounds): The number of integer solutions to \(x_1 + x_2 + \dots + x_k = n\) subject to \(x_i \ge a_i\) for \(1 \le i \le k\) (where \(N = n - (a_1 + a_2 + \dots + a_k) \ge 0\)) is:

\[\binom{N + k - 1}{k - 1}\]

Proof: Set \(x_i = y_i + a_i\). Then \(x_i \ge a_i \iff y_i \ge 0\), and the equation becomes \(y_1 + y_2 + \dots + y_k = n - \sum_{i=1}^k a_i = N\), which has \(\binom{N + k - 1}{k - 1}\) non-negative integer solutions. \(\blacksquare\)

Example 2 (Fruit Shop with Minimum Quotas): You want to buy \(20\) fruits from mangoes, oranges, and avocados, subject to buying at least \(2\) mangoes, at least \(4\) oranges, and at least \(5\) avocados. In how many ways can you do this?

Solution: We need \(x_1 + x_2 + x_3 = 20\) with \(x_1 \ge 2\), \(x_2 \ge 4\), and \(x_3 \ge 5\). Set \(x_1 = y_1 + 2\), \(x_2 = y_2 + 4\), \(x_3 = y_3 + 5\). Then \(y_1, y_2, y_3 \ge 0\) and:

\[y_1 + y_2 + y_3 = 20 - (2 + 4 + 5) = 9\]

With \(N = 9\) and \(k = 3\), the number of ways is:

\[\binom{9 + 3 - 1}{3 - 1} = \binom{11}{2} = \frac{11 \times 10}{2} = 55\]

Example 3 (Negative Lower Bounds): Find the number of integer solutions to \(x_1 + x_2 + x_3 = 10\) with \(x_1 \ge -2\), \(x_2 \ge 0\), and \(x_3 \ge 1\).

Solution: Set \(x_1 = y_1 - 2\), \(x_2 = y_2\), and \(x_3 = y_3 + 1\), so \(y_1, y_2, y_3 \ge 0\) and:

\[(y_1 - 2) + y_2 + (y_3 + 1) = 10 \implies y_1 + y_2 + y_3 = 11\]

The number of solutions is \(\binom{11 + 3 - 1}{3 - 1} = \binom{13}{2} = 78\).

Example 4 (Linear Inequalities Using a Slack Variable): Find the number of non-negative integer solutions to the inequality:

\[x_1 + x_2 + x_3 + x_4 \le 12\]

Solution: Introduce a slack variable \(x_5 = 12 - (x_1 + x_2 + x_3 + x_4)\) to absorb whatever is "left over" below \(12\). Clearly \(x_1 + x_2 + x_3 + x_4 \le 12 \iff x_5 \ge 0\), turning the inequality into an exact equation in \(5\) non-negative variables:

\[x_1 + x_2 + x_3 + x_4 + x_5 = 12, \qquad x_i \ge 0\]

Hence the number of solutions is:

\[\binom{12 + 5 - 1}{5 - 1} = \binom{16}{4} = 1820\]

Handling Upper Bounds on Variables

Now ask the natural question: what if the fruit shop does not have a sufficient supply of mangoes? Suppose the shop has only \(15\) mangoes in stock while you want to buy \(20\) fruits. Now \(x_1\) carries an upper bound: \(0 \le x_1 \le 15\).

Why are upper bounds harder than lower bounds? A variable shift \(x_1 = y_1 + a_1\) shifts a lower bound to \(0\), but cannot eliminate an upper bound. Instead, look at the opposite of an upper bound: the opposite of \(x_1 \le 15\) is the lower bound \(x_1 \ge 16\)—which we do know how to count instantly!

This pairs upper bounds cleanly with the Subtraction Principle (for a single upper bound) and with the two-set overlap formula \(|A_1 \cup A_2| = |A_1| + |A_2| - |A_1 \cap A_2|\) from Section 01 (for two upper bounds). When three or more upper bounds apply simultaneously, we use the general Principle of Inclusion–Exclusion, developed in full in Section 08.

Example 5 (Single Upper Bound): Find the number of ways to buy \(20\) fruits (\(x_1 + x_2 + x_3 = 20\), \(x_i \ge 0\)) if the shop has only \(15\) mangoes (\(x_1 \le 15\)), while oranges and avocados are in unlimited supply.

Solution:

  • Unrestricted total (\(U\)): \(\binom{20 + 3 - 1}{2} = \binom{22}{2} = 231\).
  • Opposite condition (\(A'\) — violating the upper bound): \(x_1 \ge 16\). Shift \(x_1 = y_1 + 16\) (\(y_1 \ge 0\)) to get \(y_1 + x_2 + x_3 = 4\), which has \(\binom{4 + 3 - 1}{2} = \binom{6}{2} = 15\) invalid solutions.

By the Subtraction Principle, the number of valid purchases is:

\[231 - 15 = 216\]

Example 6 (Two Upper Bounds): Find the number of non-negative integer solutions to \(x_1 + x_2 + x_3 = 15\) subject to \(x_1 \le 6\) and \(x_2 \le 7\) (with no upper bound on \(x_3\)).

Solution: Let \(U\) be all non-negative integer solutions of \(x_1 + x_2 + x_3 = 15\), so \(|U| = \binom{15 + 3 - 1}{2} = \binom{17}{2} = 136\). Define the two violation sets:

  • \(A_1\) (\(x_1 \ge 7\)): Shift by \(7 \implies\) sum \(= 8 \implies |A_1| = \binom{8 + 2}{2} = \binom{10}{2} = 45\).
  • \(A_2\) (\(x_2 \ge 8\)): Shift by \(8 \implies\) sum \(= 7 \implies |A_2| = \binom{7 + 2}{2} = \binom{9}{2} = 36\).
  • \(A_1 \cap A_2\) (\(x_1 \ge 7\) and \(x_2 \ge 8\)): Shift sum by \(15 \implies\) remaining sum \(= 0 \implies |A_1 \cap A_2| = \binom{0 + 2}{2} = 1\) (namely \((7, 8, 0)\)).

The number of invalid solutions violating at least one upper bound is \(|A_1 \cup A_2| = |A_1| + |A_2| - |A_1 \cap A_2| = 45 + 36 - 1 = 80\). Subtracting from \(|U|\) gives:

\[136 - 80 = 56 \text{ valid solutions}\]

(In Section 08, we will immediately extend this exact example by adding a third upper bound \(x_3 \le 8\) using the full Principle of Inclusion–Exclusion!)


Summary Table

Equation / Constraint Variable Conditions Number of Integer Solutions
\(x_1 + x_2 + \dots + x_k = n\) \(x_i \ge 0\) \(\binom{n + k - 1}{k - 1} = \binom{n + k - 1}{n}\)
\(x_1 + x_2 + \dots + x_k = n\) \(x_i \ge 1\) (\(n \ge k\)) \(\binom{n - 1}{k - 1}\)
\(x_1 + x_2 + \dots + x_k = n\) \(x_i \ge a_i\), \(N = n - \sum a_i \ge 0\) \(\binom{N + k - 1}{k - 1}\)
\(x_1 + x_2 + \dots + x_k \le n\) \(x_i \ge 0\) \(\binom{n + k}{k}\) (introduce slack variable \(x_{k+1} \ge 0\))
\(x_1 + x_2 + \dots + x_k = n\) \(0 \le x_i \le b_i\) Count violations \(x_i \ge b_i + 1\) and apply Subtraction / PIE