Sunday Coding
Time limit2sMemory limit512 MB
Count the distinct sequences of room-winner ranks obtainable when R rooms each hold S contestants with all ranks distinct.
- Level
Medium7 of 10
- Topics
- Combinatorics, Dynamic programming, Math
- Solved
- No attempts yet
Problem
Yeongseon is entering the online programming contest "Sunday Coding".
While the contest runs, the participants are split into rooms and each room holds participants, so there are participants in total. The rooms are numbered from to .
Nobody ties, so once the contest ends every participant receives a distinct rank from (the overall win) to .
The winner of a room is the participant with the best rank in that room.
After the contest Yeongseon writes down the rank of each room winner in room order, which gives a sequence of length . The -th number of the sequence is the rank of the winner of room .
Given and , write a program that counts the different sequences that can be produced this way.
Input
The first line contains and , separated by a space. ()
Output
On the first line, print the number of different sequences that can be produced, modulo 1,000,000,007.
Hint
For and there are two rooms with one participant each, so the sequence is either or .
For and the sequences that can be produced are , , , . Neither nor is ever possible.