Count sequences of D days, each amount in [0, X), summing to N, modulo 1e9+7.
Medium7CombinatoricsDynamic programmingMathNo attempts yetTime limit8sMemory limit512 MBGrandma left N cookies behind. My elder sister and I wanted to eat them right away, but a note was attached to the box.
My sister asked, "How many ways are there to eat all of the cookies? Let's count them!"
One way is the list of how many cookies are eaten on day 1, day 2, and so on through day D. Each daily amount is at least 0 and less than X, and the D amounts add up to exactly N. A day with no cookies at all is allowed. Two ways are different if there is a day on which the numbers of cookies eaten differ.
For example, if N, D and X are 5, 2 and 5, there are 4 ways.
The number of ways gets very large, so counting by hand is hopeless. Write a program that counts it instead.
The input consists of several datasets. There are at most 100 datasets. Each dataset is one line holding three integers N (1≤N≤2000), D (1≤D≤1012) and X (1≤X≤2000), separated by spaces. The end of the input is a line containing three zeros, and that line is not processed.
For each dataset, print the number of ways modulo 1000000007 on its own line.