#P15559. [CCPC 2025 哈尔滨站] 匹配

[CCPC 2025 哈尔滨站] 匹配

Problem Description

There are nn sets. The ii-th set has aia_i elements. There are 2m2m pairwise distinct elements in total (ai=2m\sum a_i = 2m). Each element belongs to exactly one set.

In each round of operation, we randomly match all elements into mm 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 998244353998244353.

Input Format

The first line contains an integer TT (1T1001 \le T \le 100), the number of testcases.

Then for each testcase:

Line 11 contains two integers n,mn, m (1n2m4001 \le n \le 2m \le 400), representing the initial number of sets and the number of pairs matched in each round.

Line 22 contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai2×m1 \le a_i \le 2 \times m, ai=2×m\sum a_i = 2 \times m), where aia_i denotes the number of elements in the ii-th set.

It is guaranteed that over all testdata, n800\sum n \le 800 and m400\sum m \le 400.

Output Format

For each testcase, output one integer per line representing the answer modulo 998244353998244353.

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 11:

  • Testcase 1: We represent the initial state as [1,1][1,1]. There is only 11 possible matching, and no matter which of the 22 elements is chosen, after one round the state becomes [2][2]. Therefore the expected answer is 11.
  • Testcase 2: We represent the initial state as [2,2][2,2]. There are 33 possible matchings. For each matching, there are 44 ways to choose elements, so there are 1212 different operations in total. Among them, 44 operations lead to state [4][4], and the other 88 operations lead to state [2,2][2,2]. That is, with probability 13\frac{1}{3}, after the operation only one set remains; otherwise the state does not change. Therefore the expectation is 33.
  • Testcase 3: We represent the initial state as [1,3][1,3]. There are 1212 different operations in total. Among them, 66 operations lead to state [4][4], and the other 66 operations lead to state [2,2][2,2]. Therefore the expectation is 1+12×3=521+\frac{1}{2}\times 3=\frac{5}{2}, which is 499122179499122179 modulo 998244353998244353.
  • Testcase 4: We represent the initial state as [1,1,2][1,1,2]. There are 1212 different operations in total. Among them, 22 operations lead to state [4][4], and the other 1010 operations lead to state [2,2][2,2]. Therefore the expectation is 1+56×3=721+\frac{5}{6}\times 3=\frac{7}{2}, which is 499122180499122180 modulo 998244353998244353.

Translated by ChatGPT 5