2D-DP,Memoization, Easy to understand C++
\n\n# Complexity\n- Time complexity: O(mn)\n\n- Space complexity: O(mn)\n\n\n# Code\n\nclass Solution {\npublic:\n    int f(vector<vector<int>>&dp,vector<vector
\n\n# Complexity\n- Time complexity: O(m*n)\n\n- Space complexity: O(m*n)\n\n\n# Code\n```\nclass Solution {\npublic:\n    int f(vector<vector<int>>&dp,vector<vector<int>>&grid,int i,int j)\n    {\n        if(i>=grid.size() || j>=grid[0].size()) return 0;\n        if(dp[i][j]!=-1) return dp[i][j];\n        int rowTake=INT_MIN, colTake=INT_MIN;\n        if(i<grid.size()-1)rowTake=grid[i+1][j]-grid[i][j]+f(dp,grid,i+1,j);\n        if(j<grid[0].size()-1)colTake=grid[i][j+1]-grid[i][j]+f(dp,grid,i,j+1);\n        return dp[i][j]=max(0,max(colTake,rowTake));\n    }\n    int maxScore(vector<vector<int>>& grid) {\n        int m=grid.size();\n        int n=grid[0].size();\n        vector<vector<int>>dp(m+1,vector<int>(n+1,-1));\n        int ans=INT_MIN;\n        for(int i=0;i<m;i++)\n        {\n            for(int j=0;j<n;j++)\n            {\n                if(i<m-1) ans=max(ans,grid[i+1][j]-grid[i][j]+f(dp,grid,i+1,j));\n                 if(j<n-1) ans=max(ans,grid[i][j+1]-grid[i][j]+f(dp,grid,i,j+1));               \n            }\n        }\n        return ans;\n    }\n};\n```
['C++']