CF1479E.School Clubs
NOI/NOI+/CTSC
通过率:0%
时间限制:4.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
In Homer's school, there are n students who love clubs.
Initially, there are m clubs, and each of the n students is in exactly one club. In other words, there are ai students in the i-th club for 1≤i≤m and a1+a2+⋯+am=n.
The n students are so unfriendly that every day one of them (chosen uniformly at random from all of the n students) gets angry. The student who gets angry will do one of the following things.
- With probability 21, 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 21, 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 k clubs and there are bi students in the i-th club for 1≤i≤k (before the student gets angry). He leaves his current club, and then joins the i-th club with probability nbi.
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 0 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 qp with gcd(p,q)=1. Therefore, you are asked to find the value of pq−1mod998244353. It can be shown that qmod998244353=0 under the given constraints of the problem.
在荷马的学校中,有 n 名热爱社团的学生。
最初,共有 m 个社团,且这 n 名学生每人恰好属于其中一个社团。换言之,对 1≤i≤m,第 i 个社团中有 ai 名学生,且满足 a1+a2+⋯+am=n。
这 n 名学生彼此十分不友好,因此每天会有一名学生(从全部 n 名学生中等概率随机选出)发怒。该发怒的学生将执行以下两种行为之一:
- 以概率 21,他离开当前所在的社团,然后自己创建一个新社团并加入其中。他所创建的新社团中仅有他自己一名学生;
- 以概率 21,他不创建新社团。此时,他将离开当前社团,并以与各社团人数成正比的概率,转入某个新的社团(也可能是他当前所在的社团)。形式化地,假设当前共有 k 个社团,且第 i 个社团中有 bi 名学生(1≤i≤k,此为该学生发怒前的状态),则他离开当前社团后,加入第 i 个社团的概率为 nbi。
注意:当某个社团人数变为 0 后,它将永远保持空置状态,因为根据上述规则,任何发怒的学生加入一个空社团的概率均为 0。
荷马想知道:首次出现所有 n 名学生均处于同一社团所需天数的期望值。
可以证明,该期望值可表示为最简分数形式 qp(即 gcd(p,q)=1)。因此,你需要计算 pq−1mod998244353 的值。在本题给定的约束条件下,可以保证 qmod998244353=0。
输入格式
The first line contains an integer m (1≤m≤1000) — the number of clubs initially.
The second line contains m integers a1,a2,…,am (1≤ai≤4⋅108) with 1≤a1+a2+⋯+am≤4⋅108, where ai denotes the number of students in the i-th club initially.
第一行包含一个整数 m(1≤m≤1000)—— 表示初始的社团数量。
第二行包含 m 个整数 a1,a2,…,am(1≤ai≤4⋅108),满足 1≤a1+a2+⋯+am≤4⋅108,其中 ai 表示第 i 个社团初始的学生人数。
输出格式
Print one integer — the expected number of days until every student is in the same club for the first time, modulo 998244353.
输出一个整数——即所有学生首次全部进入同一社团所需的期望天数,对 998244353 取模。
输入输出样例
输入#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 41. So the expected number of days until every student is in the same club should be 4.
In the second example, we note that in the first day:
- The only student in the first club will get angry with probability 31. If he gets angry, then he will create a new club and join it with probability 21 (In this case, there will be three clubs which have 0,1,2 students in it, respectively), leave his current club and join the second club with probability 21⋅32=31, or stay still with probability 21⋅31=61;
- Each of the two students in the second club will get angry with probability 31. If one of them gets angry, then he will create a new club and join it with probability 21, leave his current club and join the second club with probability 21⋅31=61, or stay still with probability 21⋅32=31.
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 0.
在第一个例子中,无论哪位学生生气,两位学生最终进入同一社团的概率均为 41。因此,所有学生都进入同一社团所需的期望天数为 4。
在第二个例子中,我们注意到第一天的情况如下:
- 第一个社团中唯一的一名学生以概率 31 生气。若他生气,则:
- 以概率 21 创建一个新社团并加入其中(此时将存在三个社团,分别有 0、1、2 名学生);
- 以概率 21⋅32=31 离开当前社团并加入第二个社团;
- 以概率 21⋅31=61 保持不动;
- 第二个社团中的两名学生各自以概率 31 生气。若其中一人生气,则:
- 以概率 21 创建一个新社团并加入其中;
- 以概率 21⋅31=61 离开当前社团并加入第二个社团;
- 以概率 21⋅32=31 保持不动。
在第四个例子中,初始时仅有一个社团,即所有学生已处于同一社团中。因此答案为 0。
输入解题思路,AI测评打分。不知道怎么写?