标题: 【ICPC】The 2021 CCPC Weihai Onsite G [打印本页] 作者: 滴水恩情 时间: 2024-10-15 23:03 标题: 【ICPC】The 2021 CCPC Weihai Onsite G Shinyruo and KFC
#组合数学 #暴力 #枚举
题目描述
During your participation in this competition, Shinyruo is preparing to order KFC for the offline competition next week.
There are n n n kinds of foods in KFC, and he plans to order a i a_i ai number of the i i i-th food for every i ∈ [ 1 , n ] i \in [1,n] i∈[1,n]. Due to shortage of manpower, the total number of all kinds of foods is no larger than 1 0 5 10^5 105.
After the competition, he will hand all the KFC out to k k k teams. Each team can get different kinds of foods but for each kind it can get one at most.
Now Shinyruo wants to know the number of ways to hand the desserts out. As he doesn’t know the number of participating teams, you need to calculate the answers for k = 1 , 2 , ⋯ , m k=1,2,\cdots,m k=1,2,⋯,m.
As the answer can be large, print it modulo 998244353 998244353 998244353.
输入格式
The first line contains two integers n , m n,m n,m. ( 1 ≤ m , n ≤ 5 ⋅ 1 0 4 1 \le m,n \le 5 \cdot 10^4 1≤m,n≤5⋅104)
The second line contains n n n integers a 1 , ⋯ , a n a_1,\cdots,a_n a1,⋯,an. ( 0 ≤ a i ≤ 1 0 5 , ∑ i = 1 n a i ≤ 1 0 5 0\le a_i\le 10^5,\ \sum_{i=1}^n a_i\le 10^5 0≤ai≤105, ∑i=1nai≤105)
输出格式
m m m lines each contains one integer. The i i i-th integer indicates the answer of k = i k=i k=i modulo 998244353 998244353 998244353.
样例 #1
样例输入 #1
4 6
0 1 2 3
复制代码
样例输出 #1
0
0
9
96
500
1800
复制代码
解法
解题思绪
轻易发现,队伍人数 > max i = 1 i ≤ n a i > \max_{i=1}^{i\leq n}a_i >maxi=1i≤nai 时,一定无解,因为根据鸽巢定理,每个人肯定被分到重复的糖果。
轻易发现,答案其实就是 ∑ j = m a x a i + 1 j ≤ n ∑ i = 1 i ≤ n C j a i \sum_{j=max_{a_i+1}}^{j\leq n} \sum_{i=1}^{i\leq n}C_{j}^{a_i} ∑j=maxai+1j≤n∑i=1i≤nCjai,但是思量到 i ≤ 5 ∗ 1 0 4 i \leq 5*10^4 i≤5∗104,直接枚举会超时。
由于 0 ≤ a i ≤ 1 0 5 , ∑ i = 1 n a i ≤ 1 0 5 0\le a_i\le 10^5,\ \sum_{i=1}^n a_i\le 10^5 0≤ai≤105, ∑i=1nai≤105,所以 a i a_i ai的种类至多有 n \sqrt n n 种,那么我们可以利用一个 m a p map map来存储类型的个数,利用快速幂加快组合数的计算即可。
由于 a i ≤ 1 0 5 a_i \leq 10^5 ai≤105,我们可以预处理出所有的阶乘,然后利用组合数的公式即可。
末了复杂度为 O ( m n l o g 2 n ) O(m\sqrt n log_2 n) O(mn log2n)
代码