👍Runtime 167 ms Beats 100.00%
Code\n\nconst mod = 1e9 + 7\n\nfunc colorTheGrid(m int, n int) int {\n\tstate := make(map[int]int64)\n\tdfs(state, 0, m, -1, 0)\n\tset := make([]int, 0, len(sta
# Code\n```\nconst mod = 1e9 + 7\n\nfunc colorTheGrid(m int, n int) int {\n\tstate := make(map[int]int64)\n\tdfs(state, 0, m, -1, 0)\n\tset := make([]int, 0, len(state))\n\tfor k := range state {\n\t\tset = append(set, k)\n\t}\n\n\tfor i := 1; i < n; i++ {\n\t\tdp := make(map[int]int64)\n\t\tfor _, a := range set {\n\t\t\tfor _, b := range set {\n\t\t\t\tif a&b == 0 {\n\t\t\t\t\tdp[a] = (dp[a] + state[b]) % mod\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tstate = dp\n\t}\n\n\tres := int64(0)\n\tfor _, val := range state {\n\t\tres = (res + val) % mod\n\t}\n\treturn int(res)\n}\n\nfunc dfs(state map[int]int64, j, m, prev, cur int) {\n\tif j == m {\n\t\tstate[cur]++\n\t\treturn\n\t}\n\tfor i := 0; i < 3; i++ {\n\t\tif i == prev {\n\t\t\tcontinue\n\t\t}\n\t\tdfs(state, j+1, m, i, (cur<<3)|(1<<i))\n\t}\n}\n```
['Go']