ARC134C The Majority
ARC134C The Majority
小清新数学题。(反正我做不出来)
简要题意
有\(K\)个箱子,编号为\(1\)到\(K\)的箱子。起初,所有箱子都是空的。
史努克有一些球,球上写着\(1\)到\(N\)的整数。在这些球中,有\(a_i\)个球上写着数字\(i\)。带有相同数字的球无法区分。
史努克决定把他所有的球都放进箱子里。他希望每个箱子里写着数字\(1\)的球都是多数。换句话说,每个箱子里,写着数字\(1\)的球的数量应该多于其他球的数量,即占到一半以上。
找出这样放置球的方法数,结果对\(998244353\)取模。
当存在一对整数\((i,j)\)满足\(1≤i≤K,1≤j≤N\),并且在第\(i\)个箱子中,写着数字\(j\)的球的数量不同时,两种方式被认为是不同的。
思路
把每个 1 号球先和每个不是 1 号球配对一下,再在每个盒子里都放 1 个 1 号球。
这样子剩下了 \(a_1-\sum\limits_{i=2}^na_i-k\) 个 1 号球。
同时保证了 1 号球是多数的条件。
现在使 \(a_1-\sum\limits_{i=2}^na_i-k \to a_1\)。
接下来球都可以任意放,对于单个种类的球看做有 \(a_i\) 个球,放到 \(k\) 个盒子里,允许空放的问题。
这个经典问题的答案是 \(C_{a_i+k-1}^{k-1}\)。
最终答案是
\]
CODE
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 998244353
const int maxn=1e5+5;
ll n,k,sum,ans;
ll a[maxn],fac[maxn],inv[maxn];
ll ksm(ll x,ll y)
{
ll sum=1;
for(;y;y/=2,x=x*x%mod) if(y&1) sum=sum*x%mod;
return sum;
}
ll C(ll n,ll m)
{
if(n<=m) return 1;
ll sum=inv[m];
for(ll i=n-m+1;i<=n;i++) sum=sum*i%mod;
return sum;
}
int main()
{
scanf("%lld%lld",&n,&k);
fac[0]=1;
for(int i=1;i<=k;i++) fac[i]=fac[i-1]*i%mod;
inv[k]=ksm(fac[k],mod-2);
for(int i=k-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
for(int i=2;i<=n;i++) sum+=a[i];
a[1]=a[1]-sum-k;
if(a[1]<0)
{
printf("0");
return 0;
}
ans=1;
for(int i=1;i<=n;i++)
ans=ans*C(a[i]+k-1,k-1)%mod;
printf("%lld",ans);
}
ARC134C The Majority的更多相关文章
- [LeetCode] Majority Element II 求众数之二
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorit ...
- [LeetCode] Majority Element 求众数
Given an array of size n, find the majority element. The majority element is the element that appear ...
- 【leetcode】Majority Element
题目概述: Given an array of size n, find the majority element. The majority element is the element that ...
- [LintCode] Majority Number 求众数
Given an array of integers, the majority number is the number that occurs more than half of the size ...
- ✡ leetcode 169. Majority Element 求出现次数最多的数 --------- java
Given an array of size n, find the majority element. The majority element is the element that appear ...
- (Array)169. Majority Element
Given an array of size n, find the majority element. The majority element is the element that appear ...
- LeetCode 169. Majority Element
Given an array of size n, find the majority element. The majority element is the element that appear ...
- [UCSD白板题] Majority Element
Problem Introduction An element of a sequence of length \(n\) is called a majority element if it app ...
- Leetcode # 169, 229 Majority Element I and II
Given an array of size n, find the majority element. The majority element is the element that appear ...
- Majority Number I & || && |||
Majority Number Given an array of integers, the majority number is the number that occurs more than ...
随机推荐
- Tesla 开发者 API 指南:BLE 密钥 – 身份验证和车辆命令
注意:本工具只能运行于 mac 或者 linux, win下不支持. 1. 克隆项目到本地 https://github.com/teslamotors/vehicle-command.git 2. ...
- iptables 工作过程整理
转载注明出处: 1.概念和工作原理 iptables是Linux系统中用来配置防火墙的命令.iptables是工作在TCP/IP的二.三.四层,当主机收到一个数据包后,数据包先在内核空间处理,若发现目 ...
- bacnet mstp设备数据 转IEC61850项目案例
目录 1 案例说明 1 2 VFBOX网关工作原理 1 3 使用YABE软件读取BACNET MSTP设备信息 2 4 配置网关采集BACNET MSTP数据 4 5 用IEC61850协议转发数据 ...
- 使用 Dependify 工具探索 .NET 应用程序依赖项
在大型项目中,由于各种组件的复杂性和互连性,管理依赖项可能变得具有挑战性.如果没有适当的工具或文档,可能很难浏览项目并对依赖项做出假设.以下是在大型项目中难以导航项目依赖项的几个原因: 复杂性:大型项 ...
- 想好新年去哪了吗?合合信息扫描全能王用AI“留住”年味
还有不到十天,除夕就要到了.近几年春节假期中,有人第一次带着孩子直击海面冰风,坐船回老家:也有人选择"漫游"国内外,在旅行中迎接新春的朝气.合合信息旗下扫描全能王APP通过AI扫描 ...
- OData – How It Work
前言 OData 是很冷门的东西, 用的人少, 开发的人少, 文档自然也少的可怜. 如果真的想用它, 多少要对它机制有点了解. 这样遇到 bug, 想扩展的时候才不至于完全没有路. 主要参考: ODa ...
- Flutter Forward 活动正式发布
2023 年 1 月 25 日,Flutter 团队将在肯尼亚首都内罗毕举办 Flutter Forward 大会,并同时开启线上直播,敬请期待! 活动将于北京时间 1 月 25 日 22:30 开始 ...
- 线段树与离散化技巧 Mayor's posters——poj 2528
问题描述: 有一堵海报墙,从左到右一共有10000000个小块,墙上贴了许多海报,每张海报的高度与墙的高度相同,宽度不同,新帖的海报会将原有的海报覆盖,问当所有人把海报贴完是,墙上可以看到几张海报 输 ...
- 用C#写个PDF批量合并工具简化日常工作
一. 前言 由于项目需要编写大量的材料,以及各种签字表格.文书等,最后以PDF作为材料交付的文档格式,过程文档时有变化或补充,故此处理PDF文档已经成为日常工作的一部分. 网上有各种PDF处理工具,总 ...
- Vscode 远程切换Python虚拟环境
在VSCode中远程切换Python虚拟环境是一个涉及多个步骤的过程,包括安装必要的扩展.连接到远程服务器.创建或激活虚拟环境,并在VSCode中选择相应的Python解释器.以下是一个详细的步骤指南 ...