Python solution
Let\'s start with one roll. We can get six sequences which are 1,2,3,4,5 and 6.\n\nLet\'s roll the second time. How can we get the sequences ending with two 1s(
Let\'s start with one roll. We can get six sequences which are 1,2,3,4,5 and 6.\n\nLet\'s roll the second time. How can we get the sequences ending with two 1s(i.e., 11)? They can only be generated by adding 1 to previous sequences ending with one 1(i.e., 1). How can we get the sequences ending with one 1(i.e., 21, 31, 41, 51 and 61)? They can only be generated by adding 1 to previous sequences that are not ended with 1(i.e., 2,3,4,5 and 6). \n\nLet\'s roll n times. The number of valid sequences ending with *i*(2<=i<=rollMax[1]) 1s equals the number of sequences ending with *i-1* 1s at the previous roll. And the number of sequences ending with one 1 equals the number of all sequences not ending with 1 at previous roll. \n\nLets store the number of sequences ending with *j* 1s to ans[0][j-1], the number of sequences ending with *j* 2s to ans[1][j-1], etc. We\'ll update ans every time we roll the dice till n times. Return the sum of all elements in ans.  \n```\nclass Solution:\n    def dieSimulator(self, n: int, rollMax: List[int]) -> int:\n        ans = [[0]*_ for _ in rollMax]\n        count = 1\n        for i in ans:\n            i[0] = 1\n        while count < n:\n            total_sum = sum([sum(_) for _ in ans])\n            for i in range(len(ans)):\n                cur_sum = total_sum-sum(ans[i])\n                for j in range(len(ans[i])-1,0,-1):\n                    ans[i][j] = ans[i][j-1]\n                ans[i][0] = cur_sum\n            count += 1\n        return sum([sum(_) for _ in ans]) % (10**9+7)\n```
[]