Module 2.1 · Counting and Probability
Bijections
Many AIME counting problems look messy until you find a second set of objects that is easy to count and matches the first set one-to-one. That matching is called a bijection. Once you have it, the two sets have the same size, and the hard count becomes an easy one.
What a bijection buys you
Suppose you want , the number of objects in some awkward set . If you can describe a rule that turns each object of into an object of a nicer set , and a rule that turns each object of back into exactly one object of , then .
Definition
Bijection
A bijection between sets and is a pairing in which every element of is matched with exactly one element of and every element of is matched with exactly one element of . If a bijection exists, then .
To prove a rule is a bijection, check two things: the rule always lands in (it is well defined), and you can undo it (every object of comes from exactly one object of ). On the AIME you rarely write this out, but you should always ask yourself, "Can I run this backwards?"
Stars and bars
The most useful bijection in contest counting turns solutions of an equation into arrangements of symbols.
A solution to in nonnegative integers, such as , can be written as a row of stars split by bars:
The stars before the first bar give , the stars between the bars give , and the stars after the second bar give . Every row of stars and bars gives exactly one solution, and every solution gives exactly one row. So the number of solutions is the number of ways to choose which of the positions hold bars: .
Stars and bars
The number of solutions of in nonnegative integers is .
The number of solutions in positive integers is (choose of the gaps between stars).
Lower bounds are handled by another bijection: a shift. If , set . The map is a bijection between the solutions you want and solutions of a new equation with a smaller total.
Spreading out: gaps between chosen numbers
Choosing numbers with no two consecutive is another classic. If are chosen from with no two consecutive, then
gives chosen from with no restriction. Subtracting squeezes out the forced gaps, and adding them back undoes it. So the count is .
The same trick works for any required gap: if consecutive chosen numbers must differ by at least , subtract from .
A close cousin handles non-decreasing sequences. If , then is strictly increasing with values in , so there are such sequences.
Common mistake
Always check the range of the new objects. After , the largest possible is , not . Getting the endpoint wrong by one is the most common error with these shifts.
Lattice paths and reflection
A path of unit steps right () and up () from to is the same thing as a word with letters and letters , so there are of them.
Harder questions forbid paths from crossing a line. The reflection principle counts the bad paths by a bijection: take a bad path, find the first point where it touches the forbidden line, and reflect the rest of the path across that line. Bad paths to match exactly with all paths to the reflected endpoint.
For paths from to that never go above the line , the bad paths first touch . Reflecting the rest of the path across that line sends the endpoint to . So the good paths number
the Catalan numbers
A related fact, the ballot theorem: if candidate gets votes and gets votes with , and the votes are counted in random order, the probability that is strictly ahead the whole time is .
Worked example: Stars and bars with positive parts
How many ordered triples of positive integers satisfy ?
Line up stars. There are gaps between them, and choosing gaps for bars splits the stars into three nonempty groups. The answer is .
Worked example: No two consecutive
In how many ways can you choose numbers from so that no two chosen numbers are consecutive?
Write the chosen numbers as and set , , . Because , the are strictly increasing, and they lie in . Conversely, any numbers from give a valid choice by adding back . The answer is .
Worked example: Non-decreasing sequences
How many sequences of integers are there?
A non-decreasing sequence is the same as a multiset: it only records how many times each value appears. Let be the number of terms equal to . Then with each , which has solutions.
Worked example: Paths that stay below the diagonal
How many paths of unit steps right and up go from to and never pass above the line ?
All paths: . A bad path touches ; reflecting its remainder after the first touch gives a path to , and every path to arises this way. There are of those. So the answer is , the sixth Catalan number.
Tip
When a problem says "find the number of ordered tuples with a product condition," factor into primes. Distributing the exponent of each prime among the variables is a separate stars-and-bars count, and you multiply the results.
Practice
Find the number of ordered quadruples of integers with , , , , and .
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Find the number of -element subsets of that contain no two consecutive integers.
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Find the number of ordered quadruples of nonnegative integers with .
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Find the number of four-digit positive integers whose digits are in non-increasing order from left to right, such as or .
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Fourteen chairs are equally spaced around a round table. In how many ways can you choose of the chairs so that no two chosen chairs are next to each other?
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
In an election, candidate Ana receives votes and candidate Ben receives votes. The ballots are counted one at a time in a uniformly random order. The probability that Ana is strictly ahead of Ben after every ballot is counted is , where and are relatively prime positive integers. Find .
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Find the number of ordered triples of positive integers with .
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Find the number of -element subsets of in which any two elements differ by at least .
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Real contest practice
- 1998 AIME, Problem 7: a stars-and-bars count after a substitution that fixes the parity of each variable.
- 1998 AIME, Problem 13: pair each subset that contains the largest element with the subset that does not.