c++ Solution || easy to understand || using memoization ✅✅
\n\n# Code\n\nclass Solution {\npublic:\n    int dp[1002][1002];\n    int func(int n, int m, int i, int j, vector<vector<int>>&grid){\n        if(i>=n || j>=m) 
\n\n# Code\n```\nclass Solution {\npublic:\n    int dp[1002][1002];\n    int func(int n, int m, int i, int j, vector<vector<int>>&grid){\n        if(i>=n || j>=m) return 0;\n        if(dp[i][j]!=-1) return dp[i][j];\n        int right = INT_MIN, down = INT_MIN;\n        if(i+1<n){\n            down = grid[i+1][j]-grid[i][j] + func(n, m, i+1, j, grid);\n        }\n        if(j+1<m){\n            right = grid[i][j+1]-grid[i][j] + func(n, m, i, j+1, grid);\n        }\n        return dp[i][j] = max(0, max(right, down));\n    }\n    int maxScore(vector<vector<int>>& grid) {\n        int n = grid.size();\n        int m = grid[0].size();\n        memset(dp, -1, sizeof(dp));\n        int ans = INT_MIN;\n        int mx = INT_MIN;\n        for(int i = 0; i < n; i++){\n            for(int j = 0; j < m; j++){\n                mx = max(mx, func(n, m, i, j, grid));\n                if(i+1<n){\n                    ans = max(ans, grid[i+1][j]-grid[i][j]);\n                }\n                if(j+1<m){\n                    ans = max(ans, grid[i][j+1]-grid[i][j]);\n                }\n            }\n        }\n        if(mx==0) return ans;\n        return mx;\n    }\n};\n```
['Dynamic Programming', 'Memoization', 'C++']