编程介的小学生 2019-02-05 19:01 采纳率: 20.5%
浏览 393

请教一个有关随机数生成算法方面的算法问题,利用C语言算法的实现的过程方式

Problem Description
Teacher Mai has a game machine, which has n slots in a row, numbered from 1 to n, 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 a positive number of slots. Then, the machine generates a random permutation of {1,2,⋯,n} 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.

Teacher Mai 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 sorts the numbers in the m specific slots with numbers p1,p2,⋯,pm.

For example, if n=4,k=1,m=2,p={1,3} and the permutation generated is (2,4,1,3). The malware will pick numbers 2 and 1 and sort them, changing the permutation into (1,4,2,3). So Teacher Mai will get a score of 2 (pairs (4,2) and (4,3)) in this round. Teacher Mai wants to know the maximum expected game score he can get.

Input
There are multiple test cases.

For each test case, the first line contains three numbers n,k,m(1≤k,m≤n≤100).

The second line contains m numbers p1,p2,⋯,pm(1≤p1<p2<⋯<pm≤n).

In the i-th test case, n=10i.

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
6 2 3
1 4 5
10 3 4
2 6 7 9

Sample Output
225000005
608333402

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?