Skip to content

Dynamic programming · routine

Paths through a grid

From the top-left corner of a rows × cols grid, moving only right or down, how many different paths reach the bottom-right corner? Write grid_paths(rows, cols).

Every square is reached from the one above or the one to the left: its count is the sum of theirs. Fill the table row by row.

Run adds print(grid_paths(3, 7)) after your code, to try it.

Stuck on the idea rather than the code? The Tables and choices lesson walks through it.