How many ways: counting, nCr and inclusion-exclusion
The DP Table · Open board
Shows a table where each cell is built from cells already filled in. Counting problems fill the same kind of table, and this lesson is how to skip the table when a formula can jump straight to the cell.
Before you start.The clock that wraps around gave you the modulus, a fixed clock size where only the remainder is kept, and the modular inverse, a multiply that undoes a multiply when the clock size is prime. Clinic #31: Pow(x, n) gave you fast power, which finds an inverse as a^(p − 2) mod p. Clinic #21: Unique Paths showed that counting routes across a grid fills Pascal’s triangle. The running total (prefix sums and difference arrays) cut a rectangle out of a grid by adding and subtracting, which is a small case of this lesson’s last big idea.
Lesson 78 of 96 in DSA
The rest of this lesson is part of a plan.
A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.