当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5075:Random Inversion Machine

题目描述
Squark has a game machine, which has 2n slots in a row, numbered from 1 to 2n, inclusively. He plays a game with the machine for several rounds. In each round, he divides that row into k segments with marks at boundaries between adjacent segments. Each segment must contain an even number of slots. Then, the machine generates a random permutation of {1, 2, . . . , 2n} and displays the permutation on the slots.Finally, the machine calculates the inversion number of each segment and multiplies them together to get the score of the round. The inversion number of a sequence is the number of inversions (also called inversion pairs) in the sequence.

Squark can play the game for as many rounds as he wants, but he must use different partitions in different rounds. Two partitions are considered to be different if there is a mark somewhere in one partition but not in the other. The total game score is simply the sum of the score of each round. However, the machine has been intruded by a malware, which changes the permutation before the machine calculates the score of each round. It picks each segment and sorts the numbers in the slots numbered with even numbers.

For example, if n = 2, k = 1 and the permutation generated is (2, 4, 1, 3). The malware will pick numbers 4 and 3 (because they are in slots numbered with 2 and 4) and sort them, changing the permutation into (2, 3, 1, 4). So Squark will get a score of 2 (pairs (2, 1) and (3, 1)) in this round. Squark wants to know the maximum expected game score he can get.
输入解释
The first line contains an integer T (T ≤ 104) denoting the number of the test cases. For each test case, there is one line containing two integers, n(1 ≤ n ≤ 2000) and k(1 ≤ k ≤ n) as mentioned above.
输出解释
As the answer for the problem can be very large, please calculate it as an irreducible fraction A/B and output (A·B-1) mod (109 + 7) for each test case in a separate line. Here, B-1 is the multiplicative inverse of B modulo 109 + 7. The input constraints guarantee that B and 109 + 7 are coprime, so this expression is properly defined.
输入样例
3
1 1
2 2
2 1
输出样例
500000004
250000002
166666670

提示
The maximum expected game scores in the example are 1/2, 1/4, 13/6 respectively.
来自杭电HDUOJ的附加信息
Recommend liuyiding

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5075

最后修改于 2020-10-25T23:19:31+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
9000/4500MS(Java/Others) 262144/262144K(Java/Others)