Master of Permutation Construction
Time limit2sMemory limit1024 MB
Count permutations P of length N (up to 5000) so that B = (A_P1, ..., A_PN) has at most K strict left-to-right maxima, modulo 1,000,000,007.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Combinatorics, Sorting
- Solved
- No attempts yet
Problem
Master of Array Construction Jiro wants to count the permutations of length that satisfy the conditions below, given a sequence of length . A permutation of length is a sequence that uses each integer from to exactly once.
- Sequence is defined as .
- The annoyance of is the number of integers with that satisfy the following condition.
- or
- The annoyance of is at most .
Find the number of permutations that satisfy the conditions, modulo .
Input
The first line contains and , separated by a space. (, )
The second line contains the sequence , separated by spaces. ()
Output
Print the number of permutations that satisfy the conditions, modulo .