Phone Friends
Time limit1sMemory limit1024 MB
Count ordered distributions of K identical candies to N friends where each friend gets between m and M candies, modulo 1e9+7.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Combinatorics, Prefix sum, Math
- Solved
- No attempts yet
Problem
Yunje, exhausted from delivering candy, came home and went to bed.
In a dream as sweet as candy, Yunje made imaginary friends called "phone friends." Phone friends love candy, but they never ask for a candy delivery. Instead, they come to Yunje directly, so he can just stand still and hand out the candy!
In the dream, Yunje wants to distribute candies of the same kind among phone friends, giving out all of them. The phone friends will not leave Yunje no matter how the candy is distributed, but each wants to receive at least candies. Also, no friend wants anyone other than themselves to receive more than candies.
Yunje has at least and at most candies. Find the number of ways Yunje can distribute the candy while satisfying all the phone friends.
Input
The first line gives the integers , , , . (, , )
is the number of phone friends and is the number of candies Yunje has. is the minimum number of candies each friend must receive, and is the maximum number of candies each friend can receive.
Output
Print the number of ways Yunje can distribute the candy to the phone friends while satisfying the conditions. There may be too many ways, so print the number of ways modulo .