Gift
Time limit2sMemory limit512 MB
Count sequences of length N that split into blocks where each block is 0,1,...,L-1 with L at most K, modulo 1e9+7.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Combinatorics, Math, Prefix sum
- Solved
- No attempts yet
Problem
Karev really likes simple sequences of length at most . A simple sequence of length is the sequence of the numbers from to written in this order. For example, , and are simple sequences, while , and are not.
Karev's birthday is close, so Polly wants to buy a few simple sequences and concatenate them into an interesting sequence. An interesting sequence is a sequence obtained by concatenating several simple sequences, each of length at most . For example, let . Then , , and are interesting sequences, while , and are not.
Polly has so many sequences to choose from that she cannot decide which one to pick, and she wonders how many choices she really has.
Given , the maximum length of a simple sequence Polly can buy, and , the length of the interesting sequence she wants to form, write a program that counts the different interesting sequences she could make. This number can be very large, so output it modulo .
Input
The first line contains two integers and , in this order, separated by a space.
Output
Print on the first line the number of different interesting sequences Polly can make, modulo .
Constraints
Note
For and the possible interesting sequences are , , , , , and , so the answer is 7.