python concise dfs + cache
Also called top-down DP\n First figure out the sub-problems are f(i-1, r, t+1) and f(i-1, k, 1), which are redundant.\n Just cache the solution of each f. \n\n`
* Also called top-down DP\n* First figure out the sub-problems are f(i-1, r, t+1) and f(i-1, k, 1), which are redundant.\n* Just cache the solution of each f. \n\n```\nfrom functools import lru_cache\n\nclass Solution:\n    def dieSimulator(self, n: int, rollMax: List[int]) -> int:\n        \n        @lru_cache(None)\n        def dfs(i, r, t):\n            if i == 0:\n                return 1\n            \n            s = 0\n            for k in range(6):\n                if r == k:\n                    if t < rollMax[k]:\n                        s += dfs(i-1, r, t+1)\n                else:\n                    s += dfs(i-1, k, 1)\n            return s\n        \n        return dfs(n, -1, 0) % (10 ** 9 + 7)\n
[]