Bit Masking with easy intuitive variable names
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(N*3^N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N*3^N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int mod = 1e9+7;\n    int solveUsingRecursion(int n, int m, vector<vector<int>>& grid, int row, int col){\n        if(row == n){\n            return 1;\n        }\n\n        int count = 0;\n        vector<int> color(3,0);\n        if(col>0) color[grid[row][col-1]] = 1;\n        if(row>0) color[grid[row-1][col]] = 1;\n\n        for(int c=0;c<3;c++){\n            if(color[c] == 0){\n                grid[row][col] = c;\n                if(col+1 < m){\n                    count += solveUsingRecursion(n,m,grid,row,col+1)%mod;\n                }else{\n                    count += solveUsingRecursion(n,m,grid,row+1,0)%mod;\n                }\n            }\n        }\n        return count%mod;\n    }\n\n    int solveUsingBitMasking(long long n, long long m, long long row,long long col,long long premask,long long currmask,vector<unordered_map<long long,long long>>& dp){\n        if(row == n) return 1;\n        if(dp[row].find(premask) != dp[row].end()) return dp[row][premask];\n\n        //if we reach end of row, then we will shift to row+1, and return it\'s ans.\n        if(col == m){\n            return (solveUsingBitMasking(n,m,row+1,0,currmask,0,dp)%mod);\n        }\n\n        long long count = 0;\n        for(int color=1;color<=3;color++){\n            long long upperColor = (premask >> (2*col))&3;\n            long long leftColor = -1;\n            if(col>0){\n                leftColor = (currmask>>(2*col-2))&3;\n            }\n            //00: Blank\n            //01: G\n            //10: B\n            //11: R\n            if(leftColor != color && upperColor != color){\n                count += (solveUsingBitMasking(n,m,row,col+1,premask, currmask | (color<<(2*col)), dp)%mod);\n                count = count % mod;\n            }\n        }\n        \n        if(col == 0) dp[row][premask] = count;\n        return count;\n    }\n\n\n    int colorTheGrid(int m, int n) {\n        //_______________________________________________\n        //Biggest hint for bitmasking is size of \'m\'\n        //_______________________________________________\n\n        vector<unordered_map<long long,long long>> dp(n);\n        return solveUsingBitMasking(n,m,0,0,0,0,dp);\n\n        // vector<vector<int>> grid(n, vector<int>(m, -1));\n        // vector<vector<int>> dp(n, vector<int>(m, -1));\n        // return solveUsingRecursion(n,m,grid,0,0);\n    }\n};\n```
['Dynamic Programming', 'Bitmask', 'C++']