PrevNext

Overview

Intermediate counting problems demand structure. Learn to avoid overcounting by using systematic cases and complementary counting.

This module adds high-yield techniques: stars and bars with constraints, inclusion-exclusion, derangements, and bijective counting.

Key Ideas

  • Stars and bars counts nonnegative solutions to x1++xk=nx_1+\cdots+x_k=n.
  • Inclusion-exclusion fixes overlaps: AB=A+BAB|A\cup B|=|A|+|B|-|A\cap B|.
  • Symmetry reduces cases by grouping equivalent configurations.
  • Word rearrangements with repeats use n!n1!n2!\frac{n!}{n_1!n_2!\cdots}.
  • Derangements: !n=n!k=0n(1)kk!!n = n!\sum_{k=0}^n \frac{(-1)^k}{k!}.

Core Skills

Translate to Stars and Bars

Turn constraints into x1++xk=nx_1+\cdots+x_k=n and adjust for lower bounds.

Use Inclusion-Exclusion

When constraints overlap, compute total minus overlaps instead of case-by-case.

Build Bijections

Match objects to a known set (binomial coefficients, lattice paths) to avoid overcounting.

Worked Example

How many nonnegative solutions to x+y+z=10x+y+z=10 with x2x\ge2?

Let x=x2x'=x-2. Then x+y+z=8x'+y+z=8 with nonnegative variables. The answer is (8+3131)=(102)=45\binom{8+3-1}{3-1}=\binom{10}{2}=45.

Word Rearrangements

If a word has nn letters with repeats n1,n2,n_1,n_2,\ldots, the number of distinct arrangements is n!n1!n2!\frac{n!}{n_1!n_2!\cdots}. Example: BANANA has 6!3!2!1!=60\frac{6!}{3!2!1!}=60 arrangements.

Stars and Bars with Constraints

To solve x1++xk=nx_1+\cdots+x_k=n with ximix_i\ge m_i, pre-allocate the minimum: let yi=ximiy_i=x_i-m_i, then count nonnegative solutions to y1++yk=nmiy_1+\cdots+y_k=n-\sum m_i.

If you also have upper bounds, use inclusion-exclusion on the violated boxes.

Inclusion-Exclusion (PIE)

For sets A1,,AnA_1,\ldots,A_n:

Ai=AiAiAj+AiAjAk.|\cup A_i| = \sum |A_i| - \sum |A_i\cap A_j| + \sum |A_i\cap A_j\cap A_k| - \cdots.

PIE is essential for derangements and multi-constraint counting.

Derangements

A derangement is a permutation with no fixed points. The count is

!n=n!(111!+12!13!++(1)nn!).!n = n!\left(1-\frac{1}{1!}+\frac{1}{2!}-\frac{1}{3!}+\cdots+\frac{(-1)^n}{n!}\right).

The probability of a derangement approaches 1/e1/e as nn grows.

Bijections

If you can map objects in set AA to objects in set BB one-to-one and onto, then A=B|A|=|B|. Bijections often turn hard counting into binomial coefficients.

Pigeonhole Principle

If nn objects are placed into mm boxes, some box has at least n/m\lceil n/m \rceil objects. Use it to force collisions or equal sums.

Strategy Checklist

  • Decide if order matters and if repetition is allowed.
  • Use stars and bars for integer solutions.
  • Apply inclusion-exclusion for overlapping cases.
  • Check for symmetry or bijections to reduce work.

Common Pitfalls

  • Overcounting when cases overlap.
  • Forgetting to enforce lower or upper bounds.
  • Using permutations when combinations are needed.

Example: PIE with Divisibility

How many integers from 1 to 100 are divisible by 2, 3, or 5?

A2=50|A_2|=50, A3=33|A_3|=33, A5=20|A_5|=20, A2A3=16|A_2\cap A_3|=16, A2A5=10|A_2\cap A_5|=10, A3A5=6|A_3\cap A_5|=6, A2A3A5=3|A_2\cap A_3\cap A_5|=3. So the answer is 50+33+2016106+3=7450+33+20-16-10-6+3=74.

Practice Problems

StatusSourceProblem NameDifficultyTags
AMC 12Hard
Show TagsCasework, Combinatorics
AIMEHard
Show TagsInclusion-Exclusion

Module Progress:

Join the AoPS Community!

Stuck on a problem, or don't understand a module? Join the AoPS community and get help from other math contest students.

PrevNext