Top-down DP
\nclass Solution:\n    def dieSimulator(self, n: int, rollMax: List[int]) -> int:\n        MOD = 1000000007\n        @functools.lru_cache(None)\n        def dp(
```\nclass Solution:\n    def dieSimulator(self, n: int, rollMax: List[int]) -> int:\n        MOD = 1000000007\n        @functools.lru_cache(None)\n        def dp(n, roll, count):\n            if n == 1:\n                if rollMax[roll] == count:\n                    return 5\n                else:\n                    return 6\n                \n            ret = 0\n            for i in range(6):\n                if i == roll:\n                    if count + 1 <= rollMax[i]:\n                        ret += dp(n-1, i, count+1)\n                else:\n                    ret += dp(n-1, i, 1) \n            return ret % MOD\n        \n        if n == 1:\n            return 6\n        \n        ret = 0\n        for i in range(6):\n            ret += dp(n-1, i, 1)\n        return ret % MOD\n```
[]