Combinations with Repetition and Integral Equations
In Section 06, we counted ordered arrangements when repetition is allowed any number of times (). Now we ask the unordered counterpart: in how many ways can we select objects from 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 be a multiset of distinct types of objects in unlimited supply, and suppose we wish to select objects from (without regard to order).
To see what "infinite supply" really means in practice, picture a fruit shop selling mangoes, oranges, and avocados ( types). Suppose the shop stocks mangoes, oranges, and avocados, and you want to buy fruits in total. Even if you decide to buy all oranges, the shop has in stock and can easily fulfill your order. Whenever the stock of every type is at least , "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:
- number of mangoes bought,
- number of oranges bought,
- number of avocados bought,
satisfying the linear equation:
(Notice that holds automatically since all variables are non-negative and sum to ; we do not need to write it separately.)
In general, selecting objects from types in unlimited supply is in exact bijection with finding all non-negative integer solutions to:
The Binary String Bijection§
How do we count all non-negative integer solutions of without listing them? Construct a bijection with binary strings containing zeros (0) and ones (1)!
Look at how any string of twenty 0s and two 1s encodes a unique fruit purchase:
- number of
0s to the left of the first1, - number of
0s between the two1s, - number of
0s to the right of the second1.
The two 1s act as dividers slicing the twenty 0s into three parts. Check the boundary cases carefully:
- If the first
1sits at the very left end, there are no0s before it, so . - If the two
1s sit right next to each other, there are no0s between them, so . - If the second
1sits at the very right end, there are no0s after it, so .

Every binary string of zeros and ones corresponds to one and only one non-negative solution of , 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 fruits is the number of distinct arrangements of twenty 0s and two 1s:
The General Formula§
In general, for (), we use a binary string of zeros and ones ( dividers partition a row of zeros into regions). The total string length is .
Theorem (Combinations with Unlimited Repetition): The number of unordered selections of objects from distinct types in unlimited supply—equivalently, the number of non-negative integer solutions to —is:
Example 1: How many distinct terms appear in the expansion of after combining like terms?
Solution: Every term in the expansion has the form where and . Here and , so the number of distinct terms is:
Positive Integer Solutions (At Least One of Each Type)§
Return to the fruit shop: suppose you still want to buy fruits, but now you must buy at least one mango, at least one orange, and at least one avocado. Our equation becomes:
How do we reduce this to the standard form we already solved? Make a change of variables! Define:
Why does this substitution work so cleanly? Because (and similarly ). Substituting into the equation gives:
(Intuitively, you put mango, orange, and avocado into your basket first, and now you freely choose the remaining fruits with no restrictions!) Applying our standard formula with and :
Theorem (Positive Integer Solutions): For , the number of positive integer solutions to ( for all ) is:
We prove this in two illuminating ways—both ideas are worth mastering.
Proof 1 (Variable Shift): Substitute for each . Then each and . By the non-negative solution formula, the number of solutions is:
Proof 2 (Gap Method on Binary Strings): Consider again a binary string of zeros and ones. Because every variable must satisfy , no two 1s may be adjacent (which would force a middle variable to be ), and no 1 may sit at the leftmost or rightmost end (which would force or ).
Lay out the zeros in a line. Between consecutive zeros there are exactly interior gaps. Placing the identical ones into of these interior gaps automatically guarantees at least one zero in every region! Choosing gaps out of can be done in ways.

General Lower Bounds and Linear Inequalities§
The variable-shift method handles any lower bounds —even negative integers!
Theorem (Arbitrary Lower Bounds): The number of integer solutions to subject to for (where ) is:
Proof: Set . Then , and the equation becomes , which has non-negative integer solutions.
Example 2 (Fruit Shop with Minimum Quotas): You want to buy fruits from mangoes, oranges, and avocados, subject to buying at least mangoes, at least oranges, and at least avocados. In how many ways can you do this?
Solution: We need with , , and . Set , , . Then and:
With and , the number of ways is:
Example 3 (Negative Lower Bounds): Find the number of integer solutions to with , , and .
Solution: Set , , and , so and:
The number of solutions is .
Example 4 (Linear Inequalities Using a Slack Variable): Find the number of non-negative integer solutions to the inequality:
Solution: Introduce a slack variable to absorb whatever is "left over" below . Clearly , turning the inequality into an exact equation in non-negative variables:
Hence the number of solutions is:
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 mangoes in stock while you want to buy fruits. Now carries an upper bound: .
Why are upper bounds harder than lower bounds? A variable shift shifts a lower bound to , but cannot eliminate an upper bound. Instead, look at the opposite of an upper bound: the opposite of is the lower bound —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 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 fruits (, ) if the shop has only mangoes (), while oranges and avocados are in unlimited supply.
Solution:
- Unrestricted total (): .
- Opposite condition ( — violating the upper bound): . Shift () to get , which has invalid solutions.
By the Subtraction Principle, the number of valid purchases is:
Example 6 (Two Upper Bounds): Find the number of non-negative integer solutions to subject to and (with no upper bound on ).
Solution: Let be all non-negative integer solutions of , so . Define the two violation sets:
- (): Shift by sum .
- (): Shift by sum .
- ( and ): Shift sum by remaining sum (namely ).
The number of invalid solutions violating at least one upper bound is . Subtracting from gives:
(In Section 08, we will immediately extend this exact example by adding a third upper bound using the full Principle of Inclusion–Exclusion!)
Summary Table§
| Equation / Constraint | Variable Conditions | Number of Integer Solutions |
|---|---|---|
| () | ||
| , | ||
| (introduce slack variable ) | ||
| Count violations and apply Subtraction / PIE |
Mark this section complete when you have worked through its proofs.