https://www.geeksforgeeks.org/minimum-jumps-to-reach-last-building-in-a-matrix/
DFS + cache
Given a matrix containing an integer value, In which each cell of the matrix represents height of building. Find minimum jumps needed reach from First building (0, 0) to last (n-1, m-1). Jump from a cell to next cell is absolute difference between two building heights.
Examples :
Examples :
Input : int height[][] = {{ 5, 4, 2 }, { 9, 2, 1 }, { 2, 5, 9 }, { 1, 3, 11}}; Output : 12 The minimum jump path is 5 -> 2 -> 5 -> 11. Total jumps is 3 + 3 + 6 = 12.
DFS + cache
Time complexity: (R*C)
The above problem can be solve easily by using recursion. The path to reach (m, n) must be through one of the 3 cells: (m-1, n-1) or (m-1, n) or (m, n-1). So minimum jump to reach (m, n) can be written as “minimum jump of the 3 cells plus current jump.
Time complexity of this solution is exponential.