luogu#P4678. [FJWC2018] 全排列

    ID: 3675 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP2018离散化福建排列组合前缀和

[FJWC2018] 全排列

Problem Description

Define two permutations AA and BB of length nn to be similar if, for all ii, C(A,Ai)=C(B,Bi)C(A, A_i) = C(B, B_i) holds. Here, C(P,x)C(P, x) is the number of indices jj such that Pj<xP_j < x (1jn)(1 \leqslant j \leqslant n).

For two permutations P1,P2P_1, P_2 of length nn, define the function F(P1,P2)F(P_1, P_2) as the number of pairs (l,r)(l, r) such that P1[lr]P_1[l \ldots r] is similar to P2[lr]P_2[l \ldots r] (1lrn)(1 \leqslant l \leqslant r \leqslant n), and P1[lr]P_1[l \ldots r] contains no more than EE inversion pairs.

Now you need to compute: after letting P1P_1 and P2P_2 range over all permutations of 1n1 \sim n, the sum of all F(P1,P2)F(P_1, P_2).

Input Format

The first line contains an integer TT, which denotes the number of test cases.

The next TT lines each contain two non-negative integers n,En, E.

Output Format

For each test case, output one integer per line, which is the answer modulo 109+710^9 + 7.

4
2 2
2 1
2 0
1 1
10
10
9
1

Hint

For 50%50\% of the testdata, T104,n10,E50T \leqslant 10^4, n \leqslant 10, E \leqslant 50.

For 80%80\% of the testdata, T104,n50,E106T \leqslant 10^4, n \leqslant 50, E \leqslant 10^6.

For 100%100\% of the testdata, $T \leqslant 10^4, n \leqslant 500, E \leqslant 10^6$.

Translated by ChatGPT 5