Lab · c05.s05.L1
Shortest-path DP
Saving a subproblem's answer pays exactly when the same subproblem is reached many times: the work falls from the number of calls to the number of distinct cells.
Question: When does saving a result beat recomputing it?
Frame 1 of 6: 0 of 36: nothing computed yetNo cell is computed yet: the grid shows the 36 printed costs and both counters read 0. With saving on, each cell will be computed exactly once.
0 of 36: nothing computed yet. No cell is computed yet: the grid shows the 36 printed costs and both counters read 0. With saving on, each cell will be computed exactly once.
Keyboard: Space plays or pauses, Left and Right step, Home goes to the first frame, End goes to the last frame.
Text description of this lab
A square grid of printed costs fills in row by row. Each cell shows the cheapest cost of reaching it from the top-left corner, and a gold line traces the cheapest path to the bottom-right corner, total 35. Two counters rise together: with saving on one stops at 36 computations, one per cell; with saving off the other reaches 923, because the bottom-right cell alone is recomputed 252 times.
Return to the section that hosts this lab
Caption status: synthetic. Every lab declares one of published, re-simulated, schematic, synthetic or interpolated.