Memoization | DP | C++
\nclass Solution {\n    int dfs(int i, int j, int n, int m, vector<vector<int>> &grid, vector<vector<int>> &dp) {\n        if(dp[i][j] != -1) return dp[i][j];\n
```\nclass Solution {\n    int dfs(int i, int j, int n, int m, vector<vector<int>> &grid, vector<vector<int>> &dp) {\n        if(dp[i][j] != -1) return dp[i][j];\n        \n        int a = 0, b = 0, c = 0;\n        if(i - 1 >= 0 && j + 1 < m && grid[i][j] < grid[i - 1][j + 1]) a = 1 + dfs(i - 1, j + 1, n, m, grid, dp);\n        if(j + 1 < m && grid[i][j] < grid[i][j + 1]) b = 1 + dfs(i, j + 1, n, m, grid, dp);\n        if(i + 1 < n && j + 1 < m && grid[i][j] < grid[i + 1][j + 1]) c = 1 + dfs(i + 1, j + 1, n, m, grid, dp);\n    \n        return dp[i][j] = max({a, b, c});\n    }\npublic:\n    int maxMoves(vector<vector<int>>& grid) {\n        int n = grid.size(), m = grid[0].size(), ans = 0;\n        vector<vector<int>> dp(n, vector<int>(m, -1));\n        \n        for(int j=0; j<n; j++) {\n            ans = max(ans, dfs(j, 0, n, m, grid, dp));\n        }\n        return ans;\n        \n    }\n};\n```
['Dynamic Programming', 'Memoization', 'C++']