Problem. Given an m × n grid of non-negative costs, find a path from the top-left to the bottom-right cell, moving only right or down, that minimises the sum of the costs on it.
grid = 1 3 1
1 5 1 → 7 (1 → 3 → 1 → 1 → 1)
4 2 1
Lesson 12.7 counted right-or-down paths with a sum; here we minimise over them, so the recurrence takes a min: best(r, c) = grid[r][c] + min(best(r − 1, c), best(r, c − 1)).
ML context. Dynamic time warping (DTW) is this lesson with the grid built from two sequences: cell (i, j) holds the distance between frame i of one time series and frame j of the other, and the cheapest monotonic path is the best alignment between them, tolerant of one series being faster or slower (Change D). DTW compares gestures, speech, sensor traces and gait signals, and is a strong nearest-neighbour baseline for time-series classification.