#P12992. [GCJ 2022 #1C] Intranets

    ID: 12791 Type: RemoteJudge 20000~60000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 7 Uploaded By: Tags>2022组合数学Google Code Jam

[GCJ 2022 #1C] Intranets

题目描述

Apricot Rules LLC is developing a new simplified networking protocol and wants to show off their routing algorithm. In their design, a network consists of M\mathbf{M} machines numbered from 1 to M\mathbf{M}, and each pair of machines is connected by a direct link. Each of the links is given a unique integer priority value between 1 and (M×(M1)/2)(\mathbf{M} \times (\mathbf{M} - 1)/2) and each machine routes traffic according to those priorities.

Unfortunately, the routing algorithm is too aggressive and will route all traffic from a machine through the highest priority link connected to it. This may make some groups of machines isolated from others.

Formally, we say that a machine mm uses a link \ell if (and only if) \ell is the highest priority link connected to mm. We also say that a link is active if it is used by at least one of the two machines it connects. Given the link priorities, the original network becomes partitioned into disjoint intranets. Two machines belong to the same intranet if and only if there is some path between them using only active links.

For example, as seen in the left image above, only the links with priorities 6 and 5 are active. This creates two disjoint intranets. However, in the example on the right, three links are active, which results in one intranet consisting of all 4 machines.

As part of the quality assurance team at Apricot Rules LLC, you are investigating the extent of the problem. You are interested in knowing the probability of there being exactly K\mathbf{K} intranets if the priorities are assigned uniformly at random from among the (M×(M1)/2)!(\mathbf{M} \times (\mathbf{M} - 1)/2)! ways of doing so.

输入格式

The first line of the input gives the number of test cases, T\mathbf{T}. T\mathbf{T} test cases follow. Each test case is described in a single line containing two integers M\mathbf{M} and K\mathbf{K} : the number of machines and the target number of intranets, respectively.

输出格式

For each test case, output one line containing Case # x:yx: y, where xx is the test case number (starting from 1) and yy is the sought probability computed modulo the prime 109+710^{9}+7 (10000000071000000007), which is defined precisely as follows. Represent the probability as as an irreducible fraction p/qp / q (with pp and qq being non-negative integers that minimize p+qp+q ). Then, yy must equal pq1mod109+7p \cdot q^{-1} \bmod 10^{9}+7, where q1q^{-1} is the modular multiplicative inverse of qq with respect to the modulus 109+710^{9}+7. It can be shown that under the constraints of this problem, such a number yy always exists and is unique.

3
5 2
5 1
6 3
Case #1: 428571432
Case #2: 571428576
Case #3: 47619048

提示

Sample Explanation

In Sample Case #1, consider the following situation. Let's call M=5\mathbf{M}=5 machines 1,2,3,4,51,2,3,4,5 and denote the link connecting machine aa and machine bb by (a,b)(a, b). Assume that the priorities of links $(1,2),(1,3),(1,4),(1,5),(2,3),(2,4),(2,5),(3,4),(3,5),(4,5)$ are 9,8,7,6,5,4,3,2,1,109,8,7,6,5,4,3,2,1,10, respectively. Then machines 1 and 2 use link (1,2)(1,2), machine 3 uses link (1,3)(1,3), and machines 4 and 5 use link (4,5)(4,5). Thus three links (1,2),(1,3),(4,5)(1,2),(1,3),(4,5) are active, and there are two intranets {1,2,3}\{1,2,3\} and {4,5}\{4,5\}. Since K=2\mathbf{K}=2, this situation counts the answer.

We can find that there are 15552001555200 ways to assign the priorities to have exactly 22 intranets among 10!=362880010 !=3628800 ways, so the probability is 3/73 / 7.

In Sample Case #2, the probability is 4/74 / 7.

In Sample Case #3, the probability is 1/211 / 21.

Limits

  • 1T501 \leq \mathbf{T} \leq 50.
  • 1KM/21 \leq \mathbf{K} \leq \mathbf{M} / 2.

Test Set 1 (17 Pts, Visible Verdict)

  • Time limit: 20 seconds.
  • 2M502 \leq \mathbf{M} \leq 50.

Test Set 2 (27 Pts, Hidden Verdict)

  • Time limit: 60 seconds.
  • 2M5×1052 \leq \mathbf{M} \leq 5 \times 10^{5}.