Cookie Counter
Time limit8sMemory limit512 MB
Count sequences of D days, each amount in [0, X), summing to N, modulo 1e9+7.
- Level
Medium7 of 10
- Topics
- Combinatorics, Dynamic programming, Math
- Solved
- No attempts yet
Problem
Grandma left cookies behind. My elder sister and I wanted to eat them right away, but a note was attached to the box.
- The cookies go bad, so all of them have to be eaten within days.
- Overeating is bad for you, so the number eaten on a single day has to be strictly less than .
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 , day , and so on through day . Each daily amount is at least and less than , and the amounts add up to exactly . 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 , and are , and , there are 4 ways.
- Eat 1 cookie on the first day and 4 cookies on the second day.
- Eat 2 cookies on the first day and 3 cookies on the second day.
- Eat 3 cookies on the first day and 2 cookies on the second day.
- Eat 4 cookies on the first day and 1 cookie on the second day.
The number of ways gets very large, so counting by hand is hopeless. Write a program that counts it instead.
Input
The input consists of several datasets. There are at most 100 datasets. Each dataset is one line holding three integers (), () and (), separated by spaces. The end of the input is a line containing three zeros, and that line is not processed.
Output
For each dataset, print the number of ways modulo on its own line.