当前位置:网站首页>CCPC 2021 Weihai - G. shinyruo and KFC (combination number, tips)
CCPC 2021 Weihai - G. shinyruo and KFC (combination number, tips)
2022-07-05 20:23:00 【Dimple】
G. Shinyruo and KFC
The question
Altogether n n n Kind of food , Each food has a i a_i ai individual . The total number of food should not exceed 1 0 5 10^5 105.
Now I want to share these foods with k k k personal , Everyone can take many things , But each kind of food takes at most 1 individual .
about k k k from 1 To m m m, Output the food distribution plan separately .
Answer model 998244353 998244353 998244353.
1 ≤ m , n ≤ 5 ⋅ 1 0 4 1 \le m,n \le 5 \cdot 10^4 1≤m,n≤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
Ideas
Common to one food a i a_i ai individual , among k k k personal , Each person can get one at most , Then the distribution scheme is C ( k , a i ) C(k, ai) C(k,ai).
that n Kind of food , among k The overall personal distribution plan is : ∏ i = 1 n C ( k , a i ) \prod_{i=1}^{n} C(k, a_i) ∏i=1nC(k,ai);
Re traversal m personal , In this case, the minimum time complexity is O(n * m), Overtime .
And the title says ai The total does not exceed 1e5, that ai The number of species is 1 e 5 \sqrt {1e5} 1e5 Level , For repetition, use fast power to find power .
Preprocess the inverse element to find the combination number .
In this way, the time complexity is reduced to : O ( m n l o g n ) O(m \sqrt n \ logn) O(mn logn)
Code
#include<bits/stdc++.h>
using namespace std;
#define Ios ios::sync_with_stdio(false),cin.tie(0)
#define int long long
#define fi first
#define se second
#define endl '\n'
map<int,int> mp;
const int N = 200010, mod = 998244353;
int T, n, m;
int a[N];
struct node{
int x, cnt;
}b[N];
int fac[N], inv[N], finv[N];
int qmi(int x, int y)
{
int ans = 1;
while(y)
{
if(y & 1) ans = ans * x % mod;
x = x*x % mod;
y >>= 1;
}
return ans;
}
void init(){
fac[0]=inv[0]=inv[1]=finv[0]=finv[1]=1ll;
for(int i=1;i<N;i++)fac[i]=fac[i-1]*i%mod;
for(int i=2;i<N;i++)inv[i]=(mod-mod/i)*inv[mod%i]%mod;
for(int i=2;i<N;i++)finv[i]=finv[i-1]*inv[i]%mod;
}
inline int C(int a,int b){
if(b>a)return 0;
else return fac[a]*finv[a-b]%mod*finv[b]%mod;
}
signed main(){
Ios;
cin >> n >> m;
for(int i=1;i<=n;i++) cin >> a[i], mp[a[i]]++;
int cnt = 0;
for(auto it : mp)
{
cnt++;
b[cnt] = {
it.first, it.second};
}
init();
for(int i=1;i<=m;i++)
{
int ans = 1;
for(int j=1;j<=cnt;j++)
{
ans = ans * qmi(C(i, b[j].x), b[j].cnt) % mod;
}
cout << ans << endl;
}
return 0;
}
Experience
- If n The sum of the numbers does not exceed m, Then the number of types of these numbers is m \sqrt m m Level .
边栏推荐
- Station B up builds the world's first pure red stone neural network, pornographic detection based on deep learning action recognition, Chen Tianqi's course progress of machine science compilation MLC,
- c语言oj得pe,ACM入门之OJ~
- js方法传Long类型id值时会出现精确损失
- document方法
- Sort and projection
- Schema and model
- [quick start of Digital IC Verification] 1. Talk about Digital IC Verification, understand the contents of the column, and clarify the learning objectives
- July 4, 2022 - July 10, 2022 (UE4 video tutorial MySQL)
- mongodb基操的练习
- 【数字IC验证快速入门】3、数字IC设计全流程介绍
猜你喜欢

【数字IC验证快速入门】6、Questasim 快速上手使用(以全加器设计与验证为例)

【数字IC验证快速入门】7、验证岗位中必备的数字电路基础知识(含常见面试题)

无卷积骨干网络:金字塔Transformer,提升目标检测/分割等任务精度(附源代码)...

B站UP搭建世界首个纯红石神经网络、基于深度学习动作识别的色情检测、陈天奇《机器学编译MLC》课程进展、AI前沿论文 | ShowMeAI资讯日报 #07.05

微信小程序正则表达式提取链接
![[quick start of Digital IC Verification] 7. Basic knowledge of digital circuits necessary for verification positions (including common interview questions)](/img/90/aad9d7900d686efca10140717a5c5c.png)
[quick start of Digital IC Verification] 7. Basic knowledge of digital circuits necessary for verification positions (including common interview questions)

Guidelines for application of Shenzhen green and low carbon industry support plan in 2023
![[quick start of Digital IC Verification] 9. Finite state machine (FSM) necessary for Verilog RTL design](/img/32/a156293f145417eeae8d93c539ca55.png)
[quick start of Digital IC Verification] 9. Finite state machine (FSM) necessary for Verilog RTL design

Zero cloud new UI design

Unity编辑器扩展 UI控件篇
随机推荐
Schema和Model
炒股开户最低佣金,低佣金开户去哪里手机上开户安全吗
Enter the parallel world
Convolution free backbone network: Pyramid transformer to improve the accuracy of target detection / segmentation and other tasks (with source code)
1、强化学习基础知识点
y57.第三章 Kubernetes从入门到精通 -- 业务镜像版本升级及回滚(三十)
leetcode刷题:二叉树14(左叶子之和)
Leetcode (347) - top k high frequency elements
【数字IC验证快速入门】7、验证岗位中必备的数字电路基础知识(含常见面试题)
Informatics Olympiad 1340: [example 3-5] extended binary tree
. Net distributed transaction and landing solution
B站UP搭建世界首个纯红石神经网络、基于深度学习动作识别的色情检测、陈天奇《机器学编译MLC》课程进展、AI前沿论文 | ShowMeAI资讯日报 #07.05
618 "low key" curtain call, how can baiqiushangmei join hands with the brand to cross the "uncertain era"?
Dry goods navigation in this quarter | Q2 2022
c语言oj得pe,ACM入门之OJ~
USACO3.4 “破锣摇滚”乐队 Raucous Rockers - DP
14、Transformer--VIT TNT BETR
【数字IC验证快速入门】8、数字IC中的典型电路及其对应的Verilog描述方法
ROS2专题【01】:win10上安装ROS2
Y57. Chapter III kubernetes from entry to proficiency -- business image version upgrade and rollback (30)