Playlist
InterviewTime limit2sMemory limit512 MB
Count length-P sequences over N songs where every song appears at least once and any two copies of the same song are separated by at least M other songs.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Combinatorics, Math, Implementation
- Solved
- No attempts yet
Problem
Subin solves problems at an algorithm camp while listening to music. Subin's phone stores songs, and today Subin wants to listen to songs. Subin builds a playlist that satisfies both conditions below. The same song may be added to the playlist more than once.
- Every one of the stored songs appears in the playlist at least once.
- To add a song again, at least other songs must sit between the two positions that hold it in the playlist.
A playlist is a sequence of songs, and two playlists with the same songs in a different order count separately. Given , , and , write a program that counts the playlists Subin can build.
Input
The first line contains , , and , separated by spaces. (, , )
Output
Print the number of playlists Subin can build on the first line. The count can be very large, so print it modulo 1,000,000,007.
Hint
For , , the only playlist is (song 1, song 1, song 1).
For , , no playlist exists.
For , , the playlists (song 1, song 1, song 1) and (song 2, song 2, song 2) do not count, because they leave one of the two songs out.
For , , the playlists are (song 1, song 2, song 1, song 2) and (song 2, song 1, song 2, song 1).