How can I improve my code. I've used backtracking but I run into TLE in some test cases
class Solution:\n    def colorTheGrid(self, m: int, n: int) -> int:\n        matrix = [[0]*n for _ in range(m)]\n        neighbors = [(-1,0),(0,-1)]\n        de
```class Solution:\n    def colorTheGrid(self, m: int, n: int) -> int:\n        matrix = [[0]*n for _ in range(m)]\n        neighbors = [(-1,0),(0,-1)]\n        def get_colors(r,c):\n            colors = [1,2,3]\n            ans = []\n            if r==0 and c==0:\n                return colors\n            top = left = 0\n            if r==0:\n                left=matrix[r+neighbors[1][0]][c+neighbors[1][1]]\n            elif c==0:\n                top = matrix[r+neighbors[0][0]][c+neighbors[0][1]]\n            else:\n            \n                [top,left] = [matrix[r+neighbors[0][0]][c+neighbors[0][1]],matrix[r+neighbors[1][0]][c+neighbors[1][1]]]\n            for color in colors:\n                if color not in [top,left]:\n                    ans.append(color)\n            return ans\n        \n        @lru_cache(None)\n        def backtrack(r,c,count):\n            for color in get_colors(r,c):\n                \n                matrix[r][c] = color\n                if r==m-1 and c==n-1:\n                    count+=1\n                \n                elif c<n-1:\n                    count = backtrack(r,c+1,count)\n                else:\n                    count = backtrack(r+1,0,count)\n                matrix[r][c]=0\n            return count\n        return backtrack(0,0,0)\n                    \n            \n            \n            \n            \n        ```
['Backtracking']