K-minsum of Permutations
Time limit2sMemory limit512 MB
Sum the K-minsum over all N! permutations, where K-minsum adds the minimum of every contiguous block of length at least K+1.
- Level
Hard8 of 10
- Topics
- Combinatorics, Math
- Solved
- No attempts yet
Problem
A permutation of length is a sequence built from the integers through , each used exactly once. No value repeats, so there are permutations of length .
Write the elements of a permutation in order as . The K-minsum of is
where returns the smallest of the listed numbers. It adds up the minimum of every contiguous block whose length is at least . When is greater than the inner sum is empty and contributes .
You are given and . Compute the K-minsum of each of the permutations of length and add the results together.
Input
The first line contains the permutation length and an integer , separated by a space. (, )
Output
Print on one line the sum of the K-minsum over all permutations of length , modulo 1,000,000,007.