DP || OPTIMISED || C++ || SIMPLE || EASY TO UNDERSTAND
Complexity\n- Time complexity:\nO(mn)\n\n- Space complexity:\nO(mn)\n\n# Code\n\nclass Solution {\npublic:\n    int solve(int i,int j,int &m,int &n,vector<vecto
# Complexity\n- Time complexity:\nO(m*n)\n\n- Space complexity:\nO(m*n)\n\n# Code\n```\nclass Solution {\npublic:\n    int solve(int i,int j,int &m,int &n,vector<vector<int>> &grid,vector<vector<int>> &dp){\n        if(i<0||j<0||i>=m||j>=n)return 0;\n        if(dp[i][j] != -1){\n            return dp[i][j];\n        }\n        int a=0,b=0,c=0;\n        if(i-1>=0 && j+1<n&&grid[i-1][j+1]>grid[i][j]){\n            a = solve(i-1,j+1,m,n,grid,dp);\n        }\n        if(i+1<m && j+1<n&&grid[i+1][j+1]>grid[i][j]){\n            b = solve(i+1,j+1,m,n,grid,dp);\n        }\n        if(j+1<n&&grid[i][j+1]>grid[i][j]){\n            c = solve(i,j+1,m,n,grid,dp);\n        }\n        return dp[i][j] = max({a,b,c})+1;\n    }\n    int maxMoves(vector<vector<int>>& grid) {\n        int m = grid.size(),n=grid[0].size(),i,j,ans=0;\n        vector<vector<int>> dp(m,vector<int>(n,-1));\n        for(i = 0; i < m; i++){\n                if(dp[i][0]==-1){\n                    ans = max(ans,solve(i,0,m,n,grid,dp));\n                }\n        }\n        return ans-1;\n    }\n};\n```
['Dynamic Programming', 'Recursion', 'Memoization', 'C++']