#P13969. [VKOSHP 2024] Exchange and Deletion
[VKOSHP 2024] Exchange and Deletion
题目描述
There is a classic way to remove an element from an array: swap the values of the element to be removed and the last element of the array, and then delete the last element. Unfortunately, it turned out that this method does not always preserve the order of the elements in the array. Your task is to count the number of sequences of deletions after which the initially sorted array in ascending order will remain sorted.
You are given an array of length , initially filled with numbers from to in ascending order, that is, , and an array of length , whose elements are pairwise distinct numbers from to .
There are steps performed, at the -th step the following occurs: an index is chosen from to such that , after which and are swapped (if , nothing happens). Then the last element of the array at this step, which has the index , is removed from the array.
The array is called if after performing steps the array is strictly increasing.
You are given the numbers and , count the number of good arrays . The answer may be too large, so output the remainder of the answer when divided by .
输入格式
The first line contains an integer () --- the number of test cases. In the following lines, the test cases are provided.
In the first line of each test case, the integers and are given (, ).
It is guaranteed that the sum of across all test cases does not exceed .
输出格式
For each test case, output a single integer --- the number of good arrays , taken modulo .
5
1 0
1 1
2 2
3 1
4 2
1
1
2
2
7
提示
Let's analyze the fourth test from the example. In it, and . Initially, . Let's see how changes after the first step for all possible arrays .
- . Then changes as follows: . The array is not increasing.
- . Then changes as follows: . The array is increasing.
- . Then changes as follows: . The array is increasing.
We find that there are two good arrays and , so the answer to the fourth test from the example is .