Counting or optimising paths through a grid by trying every route is exponential. Grid DP computes each cell from the cells you can arrive from, usually above and to the left. Use it for unique paths, minimum path sum or paths with obstacles when moves only go right and down. If you can move in all four directions, cells depend on each other in a loop, so use BFS or Dijkstra instead.