Problem 967
Number of Music Playlists
Hard · 30 pts · Math, Dynamic Programming, Combinatorics
Problem
Your music player has N different songs and you want a playlist of exactly GOAL songs (repeats allowed) in which every song is played at least once, and a song can only be played again after K other songs have been played since its last play. Count the playlists modulo 1000000007. Let ways[i][j] be the number of playlists of length i using exactly j different songs: the next song is either new (N - j choices) or a replay of one of the j - K songs not among the last K. Keep the counts in a 64-bit integer type (long long in C++, long in Java) and take the remainder after every addition and multiplication: adding or multiplying two remainders can be larger than a 32-bit int can hold (Python needs nothing special).
Input
A single line with N, GOAL and K.
Output
Print the number of playlists modulo 1000000007.
Constraints
0 <= K < N <= GOAL <= 100
Example input
3 3 1
Example output
6
Explanation
With N = 3, GOAL = 3 and K = 1, each playlist must contain all three songs once, so the 3! = 6 orders are the answer.