DP
\n# Code\n\nclass Solution {\n    public int maxMoves(int[][] grid) {\n        int dp[][]=new int[grid.length][grid[0].length];\n        int max=0;\n        for
\n# Code\n```\nclass Solution {\n    public int maxMoves(int[][] grid) {\n        int dp[][]=new int[grid.length][grid[0].length];\n        int max=0;\n        for(int i=1;i<grid[0].length;i++){\n            for(int j=0;j<grid.length;j++){\n                if(grid[j][i-1]<grid[j][i]){\n                    if(i==1 || dp[j][i-1]>0)dp[j][i]=Math.max(dp[j][i],1+dp[j][i-1]);\n                }\n                \n                if(j-1>=0 && grid[j-1][i-1]<grid[j][i]){\n                     if(i==1 || dp[j-1][i-1]>0)dp[j][i]=Math.max(dp[j][i],1+dp[j-1][i-1]);\n                }\n                \n                if(j+1<grid.length && grid[j+1][i-1]<grid[j][i]){\n                    if(i==1 || dp[j+1][i-1]>0) dp[j][i]=Math.max(dp[j][i],1+dp[j+1][i-1]);\n                }\n                \n                max=Math.max(max,dp[j][i]);\n                //System.out.print(dp[j][i]+" ");\n            }\n            //System.out.println();\n        }\n        return max;\n    }\n}\n```
['Java']