DP Solution 🔥🔥🔥
Approach\n Describe your approach to solving the problem. \nStandard DP approach is being followed by keeping the track of previous visited row and column.\n\n#
# Approach\n<!-- Describe your approach to solving the problem. -->\nStandard DP approach is being followed by keeping the track of previous visited row and column.\n\n# Complexity\n- Time complexity: `O(N*M)`\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: `O(N*M)`\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int dp[1001][1001];\n    int solve(vector<vector<int>>& grid, int prevr, int c){\n        int n = grid.size();\n        int m = grid[0].size();\n        if(c == m-1){\n            return 0;\n        }\n        if(dp[prevr][c]!=-1) return dp[prevr][c];\n        int maxi = 0;\n        for(int i=-1; i<=1; i++){\n            int r = prevr+i;\n            if(r<n && r>=0 && c<m-1 && grid[r][c+1] > grid[prevr][c]){\n                maxi = max(maxi, 1+solve(grid, r, c+1));\n            }\n        }\n        return dp[prevr][c] = maxi;\n    }\n    int maxMoves(vector<vector<int>>& grid) {\n        int maxi=0;\n        memset(dp, -1, sizeof(dp));\n        for(int i=0; i<grid.size(); i++){\n            maxi = max(maxi, solve(grid, i, 0));\n        }\n        return maxi;\n    }\n};\n```
['Dynamic Programming', 'Recursion', 'Memoization', 'C++']