Two more rows and columns cost about 15 times the calls. The Princeton booksite puts the cure in one line: solve each subproblem once, not over and over, and you avoid a possible exponential blow-up in the running time.
A cache gives you that with the recursion kept. This is top-down: start from the cell you want, and let each call ask for the cells it needs. Filling the table with loops is bottom-up. Here is top-down on the same grid, with a list that records when each cell finishes:
from functools import cache
def most_points_top_down(grid):
finished = []
@cache
def best(r, c):
if r < 0 or c < 0:
return -math.inf
if r == 0 and c == 0:
total = grid[0][0]
else:
total = grid[r][c] + max(best(r - 1, c), best(r, c - 1))
finished.append((r, c))
return total
return best(len(grid) - 1, len(grid[0]) - 1), finished
total, finished = most_points_top_down(grid)
print(total)
for i in range(0, len(finished), 4):
print(finished[i:i + 4])
26
[(0, 0), (0, 1), (0, 2), (0, 3)]
[(1, 0), (1, 1), (1, 2), (1, 3)]
[(2, 0), (2, 1), (2, 2), (2, 3)]
A cell off the grid returns minus infinity, the same missing neighbor as before. Number the cells by when they finish, then swap the two calls inside the max and number them again: