QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 64 MB مجموع النقاط: 100

#12854. 随机逆序对机器

الإحصائيات

Teacher Mai 有一台游戏机,上面有 $n$ 个排成一行的槽位,编号从 $1$ 到 $n$。他与这台机器进行了多轮游戏。在每一轮中,他通过在相邻槽位之间放置标记,将这一行划分为 $k$ 个段。每个段必须包含正整数个槽位。然后,机器生成一个 $\{1, 2, \dots, n\}$ 的随机排列并显示在槽位上。最后,机器计算每个段的逆序对数量,并将它们相乘得到该轮的得分。序列的逆序对数量(也称为逆序对)是指序列中逆序对的个数。

Teacher Mai 可以进行任意多轮游戏,但他必须在不同的轮次中使用不同的划分方式。如果两个划分在某处有标记而另一个没有,则认为这两个划分是不同的。总游戏得分即为每一轮得分之和。然而,机器被恶意软件入侵了,恶意软件会在机器计算每一轮得分之前改变排列。它会将 $m$ 个特定槽位 $p_1, p_2, \dots, p_m$ 中的数字进行排序。

例如,如果 $n = 4, k = 1, m = 2, p = \{1, 3\}$,生成的排列为 $(2, 4, 1, 3)$。恶意软件会挑选出数字 $2$ 和 $1$ 并将它们排序,从而将排列变为 $(1, 4, 2, 3)$。因此,Teacher Mai 在这一轮中将获得 $2$ 分(逆序对为 $(4, 2)$ 和 $(4, 3)$)。Teacher Mai 想知道他能获得的最大期望游戏得分。

输入格式

第一行包含一个整数 $T$ ($0 \le T \le 10$),表示测试用例的数量。 对于每个测试用例,第一行包含三个数字 $n, k$ 和 $m$ ($1 \le k, m \le n \le 100$)。 第二行包含 $m$ 个数字 $p_1, p_2, \dots, p_m$ ($1 \le p_1 < p_2 < \dots < p_m \le n$)。 在第 $i$ 个测试用例中,$n = 10i$。

输出格式

由于答案可能非常大,请将其计算为不可约分数 $A/B$,并输出 $(A \cdot B^{-1}) \pmod{10^9 + 7}$,每个测试用例占一行。其中 $B^{-1}$ 是 $B$ 在模 $10^9 + 7$ 下的乘法逆元。输入数据保证 $B$ 与 $10^9 + 7$ 互质,因此该表达式定义良好。

样例

样例输入 1

1
10 3 4
2 6 7 9

样例输出 1

608333402

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.