Module 03 · DSA · Worked, and deeper · about 22 min to read
Continue where you left off ×
DP, the hard shapes: digits, games and speed-ups
The DP Table · Open board
Shows a table filled one cell at a time from cells already filled. This lesson changes what a cell remembers, who is moving, and how fast a cell is filled.
Before you start. Recursion & Dynamic Programming gave you the notebook idea: solve each small copy of a question once and write the answer down. DP, five more shapes taught you to write the state (one line saying what a notebook entry means) and the recurrence (the rule that fills an entry from earlier ones). Dynamic Programming, Worked (filling the table) showed knapsack as a grid.
The idea in 30 seconds
Digit DP builds a number digit by digit, and the tight flag says whether the bound still limits the next digit.
A game table stores the score difference, so one number replaces two totals and the opponent’s best is subtracted.
Subset sum asks which totals are reachable, and a bitset makes each item one shift.
A 0/1 knapsack loop must run downward so each item is used once.
A monotone queue gives each window’s maximum in O(1) steps and cuts a window table to O(n).
When the best cut point never moves left, divide and conquer optimization cuts a layer from n² to n log n.
Read the story
Lesson 19 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 .
See plans Already a member? Sign in
Or start free : a free account opens lessons 2 and 3 of every track.
In this lesson The problem: three questions that make a plain table too slow or too big Counting digits: a state that stops at the bound (the tight flag) Two players, one number: the score difference Choose or skip: the subset-sum table Sliding windows inside a table: the monotone queue Speeding up a cut table: divide and conquer optimization The ladder Terms it explains: state, recurrence, tight, digit DP, score difference, minimax, downward, monotone queue, divide and conquer optimization, quadrangle inequality, Common mistakes, 15 ->", count_ones(10.
Review DSA
Mark as read Saved in this browser, and to your account when you sign in.