🔥Memoization with BitMasking⭐|| 💯Clean & Best Code⚡
Complexity\n\n- Time complexity:\nO((1 << m) * max(grid[i][j]) * m * n)\n\n- Space complexity:\nO((1 << m) * max(grid[i][j]))\n\n\n# Code\n# Please Upvote if it
# Complexity\n```\n- Time complexity:\nO((1 << m) * max(grid[i][j]) * m * n)\n\n- Space complexity:\nO((1 << m) * max(grid[i][j]))\n```\n\n# Code\n# Please Upvote if it helps\uD83E\uDD17\n```cpp []\nclass Solution {\npublic:\n    int dp[101][1024];\n    int helper(int prev_val, vector<vector<int>>& grid, int mask){\n        if(dp[prev_val][mask] != -1)\n            return dp[prev_val][mask];\n        int maxi = 0;\n        for(int row = 0 ; row < grid.size() ; row++){\n            if(!(mask & (1 << row))){\n                for(auto it : grid[row]){\n                    if(it > prev_val)\n                        maxi = max(maxi, it + helper(it, grid, mask | (1 << row)));\n                }\n            }\n        }\n        return dp[prev_val][mask] = maxi;\n    }\n\n    int maxScore(vector<vector<int>>& grid) {\n        int m = grid.size(), n = grid[0].size();\n        memset(dp, -1, sizeof(dp));\n        return helper(0, grid, 0);\n    }\n};\n```
['Array', 'Dynamic Programming', 'Bit Manipulation', 'Memoization', 'Matrix', 'Bitmask', 'C++']