#P9919. 「RiOI-03」A Journey to the Moonlight
「RiOI-03」A Journey to the Moonlight
Background

(The picture is from a Phigros music illustration. Please contact for removal if there is any infringement.)
KDOI’s business has expanded to the Moon. However, the Internet speed on the Moon is very slow, so they need to solve the network speed problem.
KDOI’s staff have developed a new type of wireless LAN module, Wife (WIreless Fidelity Extend). Each module can connect to at most two users, and it can choose to provide unit of bandwidth to one of the connected users. However, no matter how many modules provide bandwidth to the same user at the same time, the user’s total bandwidth is always .
The employees are very lazy, often delaying a PPT for a whole month. So they are also too lazy to label the Wife modules, meaning all modules are indistinguishable from each other. In addition, to save electricity, no two modules are allowed to have exactly the same set of users they serve.
Now there are users who purchased the service. When the Wife system officially starts, the router (Lu-you-qi) finds a problem: some users may have no broadband to use. Kaitou has no Wife modules in hand, so he can only grab one, sacrifice one user’s interests, and provide broadband to all users who have broadband in a certain order. However, the users without broadband are very demanding: as long as they are not provided broadband consecutively in their registration order, they will threaten the router to refund.
Kaitou has already forgotten their registration times, so he can only randomly choose a permutation of to decide the order of providing broadband. To minimize the number of attempts, he will adjust which users are connected by Wife. He wants to know the minimum expected number of attempts needed to calm the customers’ anger.
In particular, Wife has two models. Model may choose to connect to only one user, while model must connect to two different users. You need to compute the answers for both models separately.
Kaitou surely won’t will do it himself, so he asks you to compute the result for all . Considering that you would be exhausted if you reported them one by one, the kind router will give you an array , and you only need to output .
Problem Description
Formal statement
For a bipartite graph with right-side vertices, define its weight as follows:
- Choose a matching, and mark the first matched right-side vertex. If no such vertex exists, then mark the first unmatched right-side vertex.
- Each time, randomly choose a permutation of . Stop when the unmatched right-side vertices and the marked vertex appear as a contiguous subsegment in the permutation in increasing label order.
- is the minimum expected number of operations among all matchings.
Call this bipartite graph -legal if and only if:
- Every left-side vertex has degree between and .
- For any two left-side vertices, the sets of their adjacent vertices are not identical.
Define as the sum of over all -legal bipartite graphs with right-side vertices, where left-side vertices are indistinguishable.
Given , compute .
Input Format
The first line contains two positive integers and the Wife model .
The second line contains non-negative integers .
Output Format
Output one non-negative integer, the answer.
2 1
1 1 1
15
3 2
1 1 1 1
40
12 1
1 1 4 5 1 4 1 9 1 9 8 1 0
721168027
Hint
By convention, a left-side vertex connected to right-side vertices numbered is written as .
Explanation of Sample 1
For , the answers are clearly .
For , the possible bipartite graphs are (each left-side vertex is represented by the tuple of its adjacent vertices):
$\{(1),(2)\},\{(1,2),(2)\},\{(1,2),(1)\},\{(1,2),(1),(2)\}$
Graphs with the same expectation are grouped together. The answer is , so the output is .
Explanation of Sample 2
For , the answers are .
For , the possible bipartite graphs are (each left-side vertex is represented by the tuple of its adjacent vertices):
The answer is $\dfrac61+\dfrac61\times 3+\dfrac62\times 3+\dfrac66=34$.
Constraints
For of the testdata, , , and .
This problem uses bundled testcases.
| Special property | ||||
|---|---|---|---|---|
Translated by ChatGPT 5