[EASY] Machine Learning + Web Development + Blockchain + AR/VR + Bitset DP
This problem can be easily solved using Machine Learning + Web Development + Blockchain + AR/VR + Bitset DP:\n\nclass Solution {\npublic:\n    void backtrack(lo
* This problem can be easily solved using Machine Learning + Web Development + Blockchain + AR/VR + Bitset DP:\n```\nclass Solution {\npublic:\n    void backtrack(long curr, int m, vector<int>& states) {\n        if (m == 0) {\n            states.push_back(curr);\n            return;\n        }\n        \n        for (int i = 1; i < 4; ++i) {\n            if (i != (curr & 0b11)) {\n                backtrack((curr << 2) + i, m - 1, states);\n            }\n        }\n    }\n    \n    bool is_consistent(int state1, int state2, int m) {\n        \n        for (int i = 0; i < m; ++i) {\n            if ( (state1 & 0b11) == (state2 & 0b11) ) {\n                return false;\n            }\n            state1 >>= 2;\n            state2 >>= 2;\n        }\n        return true;\n    }\n    \n    int colorTheGrid(int m, int n) {\n        vector <int> states;\n        int MOD = 1000000007, ans = 0;\n        \n        backtrack(0, m, states);\n        \n        unordered_map <int, vector <int>> prev;\n        \n        for (int state1: states) {\n            for (int state2: states) {\n                if (is_consistent(state1, state2, m)) {\n                    prev[state1].push_back(state2);\n                }\n            }\n        }\n        \n        int limit = 0;\n        \n        for (int i = 0; i < m; ++i) {\n            limit <<= 2;\n            limit += 0b11;\n        }\n        vector <vector<int>> dp(n, vector<int>(limit + 1, 0));\n        \n        for (int state: states) {\n            dp[0][state] = 1;\n            \n            if (0 == n - 1) {\n                ans += dp[0][state];\n            }\n        }\n        \n        for (int i = 1; i < n; ++i) {\n            for (int state: states) {\n                for (int prev_state: prev[state]) {\n                    dp[i][state] = (dp[i][state] + dp[i - 1][prev_state]) % MOD;\n                }\n                \n                if (i == n - 1) {\n                    ans = (ans + dp[i][state]) % MOD;\n                }\n            }\n        }\n        \n        return ans;\n        \n    }\n};\n```
[]