C++ || Recursion + Memoization || Beginner Friendly 🔥✅💯🤩
\n\n# Code\n\nclass Solution {\npublic:\n    int solve(int i, int j, vector<vector<int>>& grid, vector<vector<int>>& dp) {\n        if (i >= grid.size() || j >=
\n\n# Code\n```\nclass Solution {\npublic:\n    int solve(int i, int j, vector<vector<int>>& grid, vector<vector<int>>& dp) {\n        if (i >= grid.size() || j >= grid[0].size()) return 0;\n        if (dp[i][j] != -1) return dp[i][j];\n\n        int pick1 = INT_MIN, pick2 = INT_MIN;\n        if (i + 1 < grid.size()) pick1 = grid[i + 1][j] - grid[i][j] + solve(i + 1, j, grid, dp);\n        if (j + 1 < grid[0].size()) pick2 = grid[i][j + 1] - grid[i][j] + solve(i, j + 1, grid, dp);\n\n        dp[i][j] = max(0, max(pick1, pick2));\n        return dp[i][j];\n    }\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, vector<int>(n, -1));\n        int maxi = INT_MIN;\n        int maxi1 = INT_MIN;\n        for(int i = 0; i < m; i++) {\n            for(int j = 0; j < n; j++) {\n                maxi = max(maxi, solve(i, j, grid, dp));\n                if(i+1 < m) maxi1 = max(maxi1, grid[i+1][j] - grid[i][j]);\n                if(j+1 < n) maxi1 = max(maxi1, grid[i][j+1] - grid[i][j]);\n            }\n        }\n        if(maxi == 0) return maxi1;\n        return maxi;\n    }\n};\n```
['Dynamic Programming', 'Recursion', 'Memoization', 'C++']