DP || AVS
\n# Code\ncpp []\nclass Solution {\npublic:\n    int dp[1005][1005];\n    int fn(vector<vector<int>>& grid, int i, int j) {\n        int n = grid.size(), m = gr
\n# Code\n```cpp []\nclass Solution {\npublic:\n    int dp[1005][1005];\n    int fn(vector<vector<int>>& grid, int i, int j) {\n        int n = grid.size(), m = grid[0].size();\n        if (i == n || j == m)\n            return 0;\n        if (dp[i][j] != -1)\n            return dp[i][j];\n\n        int ans = 0;\n        if (i + 1 < n && j + 1 < m && grid[i][j] < grid[i + 1][j + 1])\n            ans = max(ans, fn(grid, i + 1, j + 1) + 1);\n\n        if (i - 1 >= 0 && j + 1 < m && grid[i][j] < grid[i - 1][j + 1])\n            ans = max(ans, fn(grid, i - 1, j + 1) + 1);\n\n        if (j + 1 < m && grid[i][j] < grid[i][j + 1])\n            ans = max(ans, fn(grid, i, j + 1) + 1);\n\n        return dp[i][j] = ans;\n    }\n    int maxMoves(vector<vector<int>>& grid) {\n            memset(dp, -1, sizeof(dp));\n        int ans = 0;\n        for (int i = 0; i < grid.size(); i++) {\n            ans = max(ans, fn(grid, i, 0));\n        }\n        return ans;\n    }\n};\n```
['C++']