#P10547. [THUPC 2024 决赛] 排列游戏

[THUPC 2024 决赛] 排列游戏

Background

An extra 1-second time limit is provided.

Problem Description

There are nn cells arranged in a row, numbered from left to right as 1,2,,n1,2,\cdots,n. Each cell has a number card. Initially, the number on the card in cell ii is ii.

The shuffler will perform nn swap operations to permute these cards: each time, they choose two cells i,ji,j (iji\ne j), and then swap the cards in cell ii and cell jj. After the nn swap operations, the permutation of the cards is completed.

Then it is the player's turn. The player also uses swap operations, swapping two cards each time, with the goal of restoring the order of these cards to the initial state.

The time needed to swap the cards in cell ii and cell jj is ij|i-j|. The player plans to restore the permutation in the shortest total time. Ask: how many possible permutations are there such that the player can complete the restoration with a total time of at most mm? Two permutations are different if and only if there exists at least one number card whose cell position differs between the two permutations.

Input Format

Each test point consists of multiple test cases.

The first line contains a positive integer TT, indicating the number of test cases. It is guaranteed that T1,000T\le1,000.

Then follow TT lines. Each line contains one test case with two positive integers nn and mm. It is guaranteed that 2n5002\le n\le500 and m5,000m\le5,000.

Output Format

For each test case, output one line with one integer representing the answer.

Since the answer may be very large, output the result modulo 1,000,000,0071,000,000,007.

6
2 1
3 1
5 2
7 5
10 20
15 24

1
2
7
331
1570446
73880648

Hint

In the first test case, the shuffler's 22 operations can only be swapping the cards in cell 11 and cell 22, so there is only 11 possible permutation, namely the initial state [1,2][1,2].

In the second test case, there are 22 possible permutations: [1,3,2][1,3,2] and [2,1,3][2,1,3]. Note that the initial state [1,2,3][1,2,3] is not a possible permutation, because after the shuffler performs the first 22 swaps, either all cards are still in the initial state (the first 22 swaps are on the same pair of cards), or none of the cards are in their initial positions (the first 22 swaps are not on the same pair of cards). After the third swap, it is impossible to return to the initial state.

In the third test case, there are 77 possible permutations: [1,2,3,5,4][1,2,3,5,4], [1,2,4,3,5][1,2,4,3,5], [1,2,5,4,3][1,2,5,4,3], [1,3,2,4,5][1,3,2,4,5], [1,4,3,2,5][1,4,3,2,5], [2,1,3,4,5][2,1,3,4,5], [3,2,1,4,5][3,2,1,4,5].

Source and Acknowledgements

From the THUPC2024 Finals (Tsinghua University Student Programming Contest and Intercollegiate Invitational, 2024). Thanks to THUSAA for providing the problem.

For the testdata, statement, reference solution, editorial, etc., please refer to the THUPC official repository https://thusaac.com/public.

Translated by ChatGPT 5