[Python] Recursion with memo.
Python\nclass Solution:\n    def dieSimulator(self, n: int, rollMax: List[int]) -> int:\n        memo = {}\n        def dfs(last, s,  k):\n            if k == n
```Python\nclass Solution:\n    def dieSimulator(self, n: int, rollMax: List[int]) -> int:\n        memo = {}\n        def dfs(last, s,  k):\n            if k == n:\n                return 1\n            if (last, s, k) not in memo:\n                res = 0\n                for i in range(6):\n                    if i == last:\n                        if s + 1 > rollMax[i]:\n                            continue\n                        else:\n                            res += dfs(i, s+1, k+1)\n                    else:\n                        res += dfs(i, 1, k+1)\n                memo[last, s, k] = res%(10**9 + 7)\n            return memo[last, s, k]\n        return dfs(None, 0, 0)%(10**9 + 7)\n```
[]