Very short python solution, faster than 89.95%
Using DP to divide the problem.\n\nf(n)   -- number of sequences for n rolls\ng(n,k) -- number of sequences for n rolls and the last number is k (1<=k<=6)\n\nf(
Using DP to divide the problem.\n\n`f(n)`   -- number of sequences for n rolls\n`g(n,k)` -- number of sequences for n rolls and the last number is `k (1<=k<=6)`\n\n**f(n) = g(n,1) + g(n,2) + ... + g(n,6)**\n\nNow it comes the most difficult part for how to get `g(n,k)`. For example, when `k = 3` and `rollMax[3] = 2`\n\nThe following is the only one sequence that is not allowed when the nth roll is 3. (x is any but not 3)\n\n```\nn-3 n-2 n-1 n\n x   3   3  3\n```\n\nSo the number of sequences of this not allowed is `f(n-3) - g(n-3,3)`. And then we get \n\n**g(n,k) = f(n-1) - f(n-R[k-1]-1) + g(n-R[k-1]-1,k)**\n\n```\nimport functools\nclass Solution:\n    def dieSimulator(self, n, R):\n\n        @functools.lru_cache(None)\n        def g(n,k):\n            if n < 1: return 0\n            if n == 1: return 1\n            return f(n-1) - f(n-R[k-1]-1) + g(n-R[k-1]-1,k)\n\n        @functools.lru_cache(None)\n        def f(n):\n            if n < 0 : return 0\n            if n == 0 : return 1\n            return sum([g(n,k) for k in range(1,7)])\n\n        return f(n) % (10 ** 9 + 7)\n```
[]