DFS from every cell, tracking the longest path from each.
Without memoization, you recompute paths from the same cell multiple times. Overlapping subproblems make this exponential.
Can you reuse computed results?
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
The trap
DFS from every cell, tracking the longest path from each.
Without memoization, you recompute paths from the same cell multiple times. Overlapping subproblems make this exponential.
Can you reuse computed results?