编程介的小学生 2017-11-01 00:11 采纳率: 20.5%
浏览 848
已采纳

Random Inversion Machine

Problem Description
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.

Input
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.

Output
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.

Sample Input
3
1 1
2 2
2 1

Sample Output
500000004
250000002
166666670

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图