Permutation Descent Counts
Time limit2sMemory limit512 MB
Count permutations of order N with exactly v descents, modulo 1001113, for up to 1000 queries with N at most 100.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Combinatorics, Math, Prefix sum
- Solved
- No attempts yet
Problem
For a positive integer , a permutation of order is a one to one function from the set of integers 1 through onto itself. Such a function is written as the list of its values, [p(1) p(2) ... p(N)].
For example, [5 6 2 4 7 1 3] is the function on {1, ..., 7} that sends 1 to 5, 2 to 6, and so on through 7 to 3.
A descent of a permutation is an integer with . The permutation [5 6 2 4 7 1 3] has a descent at 2 (6 > 2) and at 5 (7 > 1).
Let be the number of descents of , so of [5 6 2 4 7 1 3] is 2. The identity permutation is the only permutation with , and the reversing permutation given by is the only permutation with .
The permutation descent count is the number of permutations of order with . For order 3:
- , counting
[1 2 3] - , counting
[1 3 2],[2 1 3],[2 3 1],[3 1 2] - , counting
[3 2 1]
Compute for the given and . The counts get very large, so the answer and every intermediate value are taken modulo 1001113.
Input
The first line contains one integer (), the number of data sets that follow. Every data set is processed in the same way and independently of the others.
Each data set is one line. It contains the data set number , then the order (), then the value ().
Output
Print one line for each data set. The line holds the data set number , a single space, and modulo 1001113 as a decimal integer.