Introduction

Previously at the introductiory level of the AMC 8/10, just applying the formula itself is more prominent than the AMC 12 or early AIME level. However, harder problems are designed so that the method of direct counting is either impossible or significantly tedious. Therefore in this module, we will seek to explain many ways of restructuring an advanced counting problem to become solvable.

In the level of the AMC 12, a similar theme is that most hard counting problems have several representative patterns, transform the objects you are counting so they correspond to something simpler (bijection), count a large set and subtract the bad cases (inclusion-exclusion), or use symmetry to collapse the count (Burnside's Lemma), or using recurrences.

This module covers the core techniques, strategies, and the classical structures that appear, to give an understanding of advanced casework.

First, we recap some basic counting techniques.

Inclusion-Exclusion

Principle

For nn finite sets A1,A2,…,AnA_1, A_2, \ldots, A_n:

∣A1∪⋯∪An∣=∑i∣Ai∣−∑i<j∣Ai∩Aj∣+∑i<j<k∣Ai∩Aj∩Ak∣−⋯+(−1)n+1∣A1∩⋯∩An∣\lvert A_1 \cup \cdots \cup A_n \rvert = \sum_i \lvert A_i \rvert - \sum_{i<j} \lvert A_i \cap A_j \rvert + \sum_{i<j<k} \lvert A_i \cap A_j \cap A_k \rvert - \cdots + (-1)^{n+1}\lvert A_1 \cap \cdots \cap A_n \rvert

Equivalently, to count elements satisfying at least one of nn properties, we alternate between adding and subtracting the sizes of all intersections.

Hence, to count elements satisfying none of nn properties, otherwise known as the complement, we use

∣A1c∩⋯∩Anc∣=∣U∣−∑i∣Ai∣+∑i<j∣Ai∩Aj∣−⋯\lvert A_1^c \cap \cdots \cap A_n^c \rvert = \lvert U \rvert - \sum_i \lvert A_i \rvert + \sum_{i<j} \lvert A_i \cap A_j \rvert - \cdots

Furthermore, an element in exactly kk of the sets gets counted (k1)\binom{k}{1} times in the first sum, subtracted (k2)\binom{k}{2} times in the second, added (k3)\binom{k}{3} times in the third, and so on. The total contribution is

(k1)−(k2)+(k3)−⋯=1−(1−1)k=1\binom{k}{1} - \binom{k}{2} + \binom{k}{3} - \cdots = 1-(1-1)^k = 1

for k≥1k \geq 1, and 00 for k=0k=0. So every element in at least one set is counted exactly once. Therefore, this explains why inclusion-exclusion works.

Derangements

Another important technique that one should ensure to know is how to solve problems using derangements. A derangement of {1,2,…,n}\lbrace 1, 2, \ldots, n \rbrace is a permutation where no element appears in its original position, or in other words, a permutation with no fixed points.

Let AiA_i be the set of permutations where element ii is fixed. By the principle of inclusion-exclusion:

Dn=n!∑k=0n(−1)kk!=n!(1−1+12!−13!+⋯+(−1)nn!).D_n = n!\sum_{k=0}^{n}\frac{(-1)^k}{k!} = n!\left(1 - 1 + \frac{1}{2!} - \frac{1}{3!} + \cdots + \frac{(-1)^n}{n!}\right).

The values of derangements are hence D0=1D_0=1, D1=0D_1=0, D2=1D_2=1, D3=2D_3=2, D4=9D_4=9, D5=44D_5=44, D6=265D_6=265.

The recurrence Dn=(n−1)(Dn−1+Dn−2)D_n = (n-1)(D_{n-1}+D_{n-2}) is often more useful in problems, as it directly comes from casework. Element 11 goes to some position k≠1k \ne 1, and then either element kk goes to position 11 (Dn−2D_{n-2} arrangements) or it does not (Dn−1D_{n-1}).

As n→∞n \to \infty, Dn/n!→1/e≈0.368D_n/n! \to 1/e \approx 0.368. Something that is not necessary to know but is useful information is that for any large nn, about 36.8%36.8\% of all permutations are derangements.

Bijections and Double Counting

Bijections

A bijection between two sets AA and BB means that they have a one-to-one correspondence. Every element of AA maps to exactly one element of BB and vice versa. Hence if a bijection exists, ∣A∣=∣B∣|A| = |B|.

The important idea of bijections is that to count a complicated set AA, we find a simpler set BB you already know how to count, and exhibit a bijection A→BA \to B.

The Stars and Bars formula (n+k−1k−1)\binom{n+k-1}{k-1} that is used for distributing nn identical objects into kk bins is itself a bijection between solutions to x1+⋯+xk=nx_1 + \cdots + x_k = n and (k−1)(k-1)-element subsets of {1,…,n+k−1}\lbrace 1, \ldots, n+k-1 \rbrace.

Double Counting

Double counting means counting the same quantity in two different ways and equating the results accordingly. This often proves combinatorial identities or gives important information for a question that counting alone would not give.

Example. Prove ∑k=0n(nk)2=(2nn)\displaystyle\sum_{k=0}^n \binom{n}{k}^2 = \binom{2n}{n}.

We can think of this situation as the number of ways to choose nn people from a group of nn men and nn women. This gives (2nn)\binom{2n}{n}. Alternatively, we choose kk men and n−kn-k women for each kk, giving

∑k=0n(nk)(nn−k)=∑k=0n(nk)2.\sum_{k=0}^n \binom{n}{k}\binom{n}{n-k} = \sum_{k=0}^n \binom{n}{k}^2.

Since these are equal, we prove Vandermonde's identity in the symmetric case.

There are many other standard ways to do this.

Catalan Numbers

Catalan numbers are natural numbers that appear in many counting problems involving recursive or non-crossing structures.

The nnth Catalan number is

Cn=1n+1(2nn).C_n=\frac{1}{n+1}\binom{2n}{n}.

The first few values are

C0=1, C1=1, C2=2, C3=5, C4=14, C5=42.C_0=1,\ C_1=1,\ C_2=2,\ C_3=5,\ C_4=14,\ C_5=42.

Some common appearances of Catalan numbers are:

  • The number of sequences of nn steps right and nn steps up from (0,0)(0,0) to (n,n)(n,n) that never go above the diagonal y=xy=x is CnC_n.

  • The number of ways to fully parenthesize a product of n+1n+1 factors is CnC_n.

  • The number of ways to triangulate a convex (n+2)(n+2)-gon is CnC_n.

  • The number of ways to connect 2n2n points on a circle with nn non-crossing chords is CnC_n.

More generally, the number of paths from (0,0)(0,0) to (m,n)(m,n) using unit right and up steps that never go above the diagonal y=xy=x, meaning there are always at least as many right steps as up steps, is

m−n+1m+1(m+nn).\frac{m-n+1}{m+1}\binom{m+n}{n}.

One way to prove this is by reflection. Count all paths from (0,0)(0,0) to (m,n)(m,n), then subtract the bad paths that go above the diagonal. A bad path must touch the line y=x+1y=x+1. Reflecting the part of the path up to its first touch of this line gives a bijection with paths from (−1,1)(-1,1) to (m,n)(m,n).

Thus,

good paths=total paths−bad paths=(m+nn)−(m+nn−1)=m−n+1m+1(m+nn).\begin{aligned} \text{good paths} &= \text{total paths} - \text{bad paths} \\ &= \binom{m+n}{n} - \binom{m+n}{n-1} \\ &= \frac{m-n+1}{m+1}\binom{m+n}{n}. \end{aligned}

For the special case m=nm=n, this becomes

Cn=1n+1(2nn).C_n=\frac{1}{n+1}\binom{2n}{n}.

Solving Linear Recurrences

Furthermore, linear recurrences with constant coefficients are another type of difficult competition problem.

f(n)=c1f(n−1)+c2f(n−2)+⋯+ckf(n−k).f(n) = c_1f(n-1)+c_2f(n-2)+\cdots+c_kf(n-k).

The characteristic equation is

xk=c1xk−1+⋯+ck.x^k = c_1x^{k-1} + \cdots + c_k.

If its roots are r1,…,rkr_1,\ldots,r_k, then the general solution is

f(n)=A1r1n+A2r2n+⋯+Akrkn,f(n) = A_1r_1^n + A_2r_2^n + \cdots + A_kr_k^n,

where the constants AiA_i are determined by conditions given in the question.

For the Fibonacci recurrence f(n)=f(n−1)+f(n−2)f(n)=f(n-1)+f(n-2), the roots are ϕ=(1+5)/2\phi=(1+\sqrt5)/2 and ϕ^=(1−5)/2\hat\phi=(1-\sqrt5)/2, which gives Binet's formula:

Fn=ϕn−ϕ^n5.F_n = \frac{\phi^n-\hat\phi^n}{\sqrt5}.

These are often for more complex problems, but it may be fruitful to know.

Examples

Example 1: Inclusion-Exclusion

Problem. How many permutations of AABBCCAABBCC have no two adjacent identical letters?

Solution. First, we calculate the total arrangements of AABBCCAABBCC:

6!2!2!2!=90.\frac{6!}{2!2!2!}=90.

Let A1A_1 be the arrangements with both A's adjacent, A2A_2 be the arrangements with both B's adjacent, and A3A_3 be the arrangements with both C's adjacent.

For each ii,

∣Ai∣=5!2!2!=30.|A_i|=\frac{5!}{2!2!}=30.

If two pairs are adjacent, then there are

4!2!=12\frac{4!}{2!}=12

arrangements. Since there are (32)=3\binom{3}{2}=3 choices for the two adjacent pairs, the total contribution is 3636.

If all three pairs are adjacent, then there are

3!=63!=6

arrangements.

Thus, by inclusion-exclusion,

∣A1∪A2∪A3∣=3(30)−3(12)+6=90−36+6=60.|A_1 \cup A_2 \cup A_3| = 3(30)-3(12)+6 = 90-36+6 = 60.

Arrangements with no two adjacent identical letters are therefore

90−60=30.90-60=\mathbf{30}.

Example 2: Derangements

Problem. Five students each write their name on a card, then the cards are shuffled and redistributed. What is the probability that no student receives their own card?

Solution. We first find the total amount of permutations: 5!=1205!=120. Hence, the number of derangements is

D5=120(1−1+12−16+124−1120)=120⋅44120=44.\begin{aligned} D_5 &= 120\left(1-1+\frac{1}{2}-\frac{1}{6}+\frac{1}{24}-\frac{1}{120}\right) \\ &= 120\cdot\frac{44}{120} \\ &= 44. \end{aligned}

Probability is therefore

44120=1130.\frac{44}{120}=\mathbf{\frac{11}{30}}.

Example 3: Catalan Numbers

Problem. How many sequences of +1+1 and −1-1 of length 1010 have all partial sums nonnegative? In other words, every prefix has at least as many +1+1s as −1-1s.

Solution. This is equivalent to counting sequences of 55 steps right and 55 steps up from (0,0)(0,0) to (5,5)(5,5) that stay below the diagonal.

Thus, this is the number of paths from (0,0)(0,0) to (n,n)(n,n) staying below y=xy=x, and the number of sequences of nn values +1+1 and nn values −1-1 with all partial sums nonnegative, starting from 00, is the Catalan number

Cn=1n+1(2nn).C_n=\frac{1}{n+1}\binom{2n}{n}.

For n=5n=5:

C5=16(105)=2526=42.C_5 = \frac{1}{6}\binom{10}{5} = \frac{252}{6} = \mathbf{42}.

Example 4: Recursion

Problem. A frog starts at step 00 of a staircase. At each jump, it can go up 11 or 22 steps. How many ways can it reach step 1010?

Solution. Let f(n)f(n) be the number of ways to reach step nn.

The recurrence is

f(n)=f(n−1)+f(n−2),f(n)=f(n-1)+f(n-2),

with f(0)=1f(0)=1 and f(1)=1f(1)=1.

Then

f(2)=2,f(3)=3,f(4)=5,f(5)=8,f(6)=13,f(7)=21,f(8)=34,f(9)=55,f(10)=89.\begin{aligned} f(2)&=2, \\ f(3)&=3, \\ f(4)&=5, \\ f(5)&=8, \\ f(6)&=13, \\ f(7)&=21, \\ f(8)&=34, \\ f(9)&=55, \\ f(10)&=\mathbf{89}. \end{aligned}

Practice Problems

StatusSourceProblem NameDifficultyTags
AMC 12Hard
Show TagsCasework, Combinatorics
Berkeley Math Circle: Monthly Contest 8Hard
Show TagsCombinatorics
MathNetHard
Show TagsCombinatorics
Harvard-MIT Math TournamentHard
Show TagsCombinatorics
Harvard-MIT Mathematics TournamentHard
Show TagsCombinatorics
Harvard-MIT Mathematics TournamentHard
Show TagsCombinatorics
Harvard-MIT Mathematics TournamentHard
Show TagsCombinatorics, Factorization techniques
$10^{\text {th }}$ Annual Harvard-MIT Mathematics TournamentHard
Show TagsCombinatorics
12th Annual Harvard-MIT Mathematics TournamentHard
Show TagsCartesian coordinates, Circles, Combinatorics
Harvard-MIT Mathematics TournamentHard
Show TagsCombinatorics, Enumeration with symmetry
Harvard-MIT Mathematics TournamentHard
Show TagsCombinatorics
Harvard-MIT November TournamentHard
Show TagsCombinatorics
13th Annual Harvard-MIT Mathematics TournamentHard
Show TagsCombinatorics
Harvard-MIT November TournamentHard
Show TagsCombinatorics
Harvard-MIT November TournamentHard
Show TagsCombinatorics
Harvard-MIT November TournamentHard
Show TagsCombinatorics, Modular Arithmetic
HMMT 2014Hard
Show TagsCombinatorics
HMMT November 2017Hard
Show TagsCombinatorics, Determinants, Vectors
HMMT November 2018Hard
Show TagsCombinatorics
HMMT November 2018Hard
Show TagsCombinatorics, Other
Berkeley Math Circle: Monthly Contest 4Hard
Show TagsCombinatorics
HMMT November 2022Hard
Show TagsCombinatorics
HMMT February 2023Hard
Show TagsCombinatorics
HMMT FebruaryHard
Show TagsCombinatorics, Modular Arithmetic

Module Progress:

Join the Discord Community!

Stuck on a problem, or don't understand a module? Join the Discord and get help with your doubts while making more math friends.