#P15559. [CCPC 2025 哈尔滨站] 匹配
[CCPC 2025 哈尔滨站] 匹配
Problem Description
There are sets. The -th set has elements. There are pairwise distinct elements in total (). Each element belongs to exactly one set.
In each round of operation, we randomly match all elements into pairs. For each pair, we randomly choose one element, remove it from its original set, and move it into the set that the matched element belongs to. Ask for the expected number of rounds of operations until all elements belong to one set.
Output the answer modulo .
Input Format
The first line contains an integer (), the number of testcases.
Then for each testcase:
Line contains two integers (), representing the initial number of sets and the number of pairs matched in each round.
Line contains integers (, ), where denotes the number of elements in the -th set.
It is guaranteed that over all testdata, and .
Output Format
For each testcase, output one integer per line representing the answer modulo .
4
2 1
1 1
2 2
2 2
2 2
1 3
3 2
1 1 2
1
3
499122179
499122180
3
6 5
2 1 1 3 1 2
10 100
90 12 18 1 1 24 7 4 37 6
10 200
102 19 25 11 43 97 19 28 11 45
347465837
225202828
437065763
Hint
For Sample :
- Testcase 1: We represent the initial state as . There is only possible matching, and no matter which of the elements is chosen, after one round the state becomes . Therefore the expected answer is .
- Testcase 2: We represent the initial state as . There are possible matchings. For each matching, there are ways to choose elements, so there are different operations in total. Among them, operations lead to state , and the other operations lead to state . That is, with probability , after the operation only one set remains; otherwise the state does not change. Therefore the expectation is .
- Testcase 3: We represent the initial state as . There are different operations in total. Among them, operations lead to state , and the other operations lead to state . Therefore the expectation is , which is modulo .
- Testcase 4: We represent the initial state as . There are different operations in total. Among them, operations lead to state , and the other operations lead to state . Therefore the expectation is , which is modulo .
Translated by ChatGPT 5