Easy DP Solution in C++ using 2D DP.
Code\n\nclass Solution {\npublic:\n     int solve(vector<vector<int>>& grid, int i, int j, int prev, vector<vector<int>> &dp) {\n    int n = grid.size();\n    i
# Code\n```\nclass Solution {\npublic:\n     int solve(vector<vector<int>>& grid, int i, int j, int prev, vector<vector<int>> &dp) {\n    int n = grid.size();\n    int m = grid[0].size();\n    if (i < 0 || i >= n || j < 0 || j >= m) {\n        return 0;\n    }\n    if (prev >= grid[i][j]) {\n        return 0;\n    }\n    if (dp[i][j] != -1) {\n        return dp[i][j];\n    }\n    int op1 = solve(grid, i - 1, j + 1, grid[i][j], dp);\n    int op2 = solve(grid, i, j + 1, grid[i][j], dp);\n    int op3 = solve(grid, i + 1, j + 1, grid[i][j], dp);\n\n    return dp[i][j] = 1 + max({op1, op2, op3});\n}\n\nint maxMoves(vector<vector<int>>& grid) {\n    int n = grid.size();\n    int m = grid[0].size();\n    int ans = 0;\n    vector<vector<int>> dp(n , vector<int>(m , -1));\n    for (int i = 0; i < n; i++) {\n        int temp = solve(grid, i, 0, 0, dp);\n        ans = max(ans, temp);\n    }\n\n    return ans - 1;\n}\n};\n```
['C++']