CF1479E.School Clubs

NOI/NOI+/CTSC

通过率:0%

时间限制:4.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In Homer's school, there are nn students who love clubs.

Initially, there are mm clubs, and each of the nn students is in exactly one club. In other words, there are aia_i students in the ii-th club for 1≤i≤m1 \leq i \leq m and a1+a2+⋯+am=na_1+a_2+\dots+a_m = n.

The nn students are so unfriendly that every day one of them (chosen uniformly at random from all of the nn students) gets angry. The student who gets angry will do one of the following things.

  • With probability 12\frac 1 2, he leaves his current club, then creates a new club himself and joins it. There is only one student (himself) in the new club he creates.
  • With probability 12\frac 1 2, he does not create new clubs. In this case, he changes his club to a new one (possibly the same club he is in currently) with probability proportional to the number of students in it. Formally, suppose there are kk clubs and there are bib_i students in the ii-th club for 1≤i≤k1 \leq i \leq k (before the student gets angry). He leaves his current club, and then joins the ii-th club with probability bin\frac {b_i} {n}.

We note that when a club becomes empty, students will never join it because any student who gets angry will join an empty club with probability 00 according to the above statement.

Homer wonders the expected number of days until every student is in the same club for the first time.

We can prove that the answer can be represented as a rational number pq\frac p q with gcd⁡(p,q)=1\gcd(p, q) = 1. Therefore, you are asked to find the value of pq−1 mod 998 244 353pq^{-1} \bmod 998\,244\,353. It can be shown that q mod 998 244 353≠0q \bmod 998\,244\,353 \neq 0 under the given constraints of the problem.

在荷马的学校中,有 nn 名热爱社团的学生。

最初,共有 mm 个社团,且这 nn 名学生每人恰好属于其中一个社团。换言之,对 1≤i≤m1 \leq i \leq m,第 ii 个社团中有 aia_i 名学生,且满足 a1+a2+⋯+am=na_1+a_2+\dots+a_m = n。

这 nn 名学生彼此十分不友好,因此每天会有一名学生(从全部 nn 名学生中等概率随机选出)发怒。该发怒的学生将执行以下两种行为之一:

  • 以概率 12\frac{1}{2},他离开当前所在的社团,然后自己创建一个新社团并加入其中。他所创建的新社团中仅有他自己一名学生;
  • 以概率 12\frac{1}{2},他不创建新社团。此时,他将离开当前社团,并以与各社团人数成正比的概率,转入某个新的社团(也可能是他当前所在的社团)。形式化地,假设当前共有 kk 个社团,且第 ii 个社团中有 bib_i 名学生(1≤i≤k1 \leq i \leq k,此为该学生发怒前的状态),则他离开当前社团后,加入第 ii 个社团的概率为 bin\frac{b_i}{n}。

注意:当某个社团人数变为 00 后,它将永远保持空置状态,因为根据上述规则,任何发怒的学生加入一个空社团的概率均为 00。

荷马想知道:首次出现所有 nn 名学生均处于同一社团所需天数的期望值。

可以证明,该期望值可表示为最简分数形式 pq\frac{p}{q}(即 gcd⁡(p,q)=1\gcd(p, q) = 1)。因此,你需要计算 pq−1 mod 998 244 353pq^{-1} \bmod 998\,244\,353 的值。在本题给定的约束条件下,可以保证 q mod 998 244 353≠0q \bmod 998\,244\,353 \neq 0。

输入格式

The first line contains an integer mm (1≤m≤10001 \leq m \leq 1000) — the number of clubs initially.

The second line contains mm integers a1,a2,…,ama_1, a_2, \dots, a_m (1≤ai≤4⋅1081 \leq a_i \leq 4 \cdot 10^8) with 1≤a1+a2+⋯+am≤4⋅1081 \leq a_1+a_2+\dots+a_m \leq 4 \cdot 10^8, where aia_i denotes the number of students in the ii-th club initially.

第一行包含一个整数 mm(1≤m≤10001 \leq m \leq 1000)—— 表示初始的社团数量。

第二行包含 mm 个整数 a1,a2,…,ama_1, a_2, \dots, a_m(1≤ai≤4⋅1081 \leq a_i \leq 4 \cdot 10^8),满足 1≤a1+a2+⋯+am≤4⋅1081 \leq a_1+a_2+\dots+a_m \leq 4 \cdot 10^8,其中 aia_i 表示第 ii 个社团初始的学生人数。

输出格式

Print one integer — the expected number of days until every student is in the same club for the first time, modulo 998 244 353998\,244\,353.

输出一个整数——即所有学生首次全部进入同一社团所需的期望天数,对 998 244 353998\,244\,353 取模。

输入输出样例

  • 输入#1

    2
    1 1

    输出#1

    4
  • 输入#2

    2
    1 2

    输出#2

    18
  • 输入#3

    3
    1 1 1

    输出#3

    21
  • 输入#4

    1
    400000000

    输出#4

    0
  • 输入#5

    10
    1 2 3 4 5 6 7 8 9 10

    输出#5

    737609878

说明/提示

In the first example, no matter which student gets angry, the two students will become in the same club with probability 14\frac 1 4. So the expected number of days until every student is in the same club should be 44.

In the second example, we note that in the first day:

  • The only student in the first club will get angry with probability 13\frac 1 3. If he gets angry, then he will create a new club and join it with probability 12\frac 1 2 (In this case, there will be three clubs which have 0,1,20, 1, 2 students in it, respectively), leave his current club and join the second club with probability 12⋅23=13\frac 1 2 \cdot \frac 2 3 = \frac 1 3, or stay still with probability 12⋅13=16\frac 1 2 \cdot \frac 1 3 = \frac 1 6;
  • Each of the two students in the second club will get angry with probability 13\frac 1 3. If one of them gets angry, then he will create a new club and join it with probability 12\frac 1 2, leave his current club and join the second club with probability 12⋅13=16\frac 1 2 \cdot \frac 1 3 = \frac 1 6, or stay still with probability 12⋅23=13\frac 1 2 \cdot \frac 2 3 = \frac 1 3.

In the fourth example, there is only one club initially. That is, every student has already been in the same club. So the answer is 00.

在第一个例子中,无论哪位学生生气,两位学生最终进入同一社团的概率均为 14\frac{1}{4}。因此,所有学生都进入同一社团所需的期望天数为 44。

在第二个例子中,我们注意到第一天的情况如下:

  • 第一个社团中唯一的一名学生以概率 13\frac{1}{3} 生气。若他生气,则:
    • 以概率 12\frac{1}{2} 创建一个新社团并加入其中(此时将存在三个社团,分别有 00、11、22 名学生);
    • 以概率 12⋅23=13\frac{1}{2} \cdot \frac{2}{3} = \frac{1}{3} 离开当前社团并加入第二个社团;
    • 以概率 12⋅13=16\frac{1}{2} \cdot \frac{1}{3} = \frac{1}{6} 保持不动;
  • 第二个社团中的两名学生各自以概率 13\frac{1}{3} 生气。若其中一人生气,则:
    • 以概率 12\frac{1}{2} 创建一个新社团并加入其中;
    • 以概率 12⋅13=16\frac{1}{2} \cdot \frac{1}{3} = \frac{1}{6} 离开当前社团并加入第二个社团;
    • 以概率 12⋅23=13\frac{1}{2} \cdot \frac{2}{3} = \frac{1}{3} 保持不动。

在第四个例子中,初始时仅有一个社团,即所有学生已处于同一社团中。因此答案为 00。

输入解题思路,AI测评打分。不知道怎么写?

首页