ARC134C The Majority

link:【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}\)。

最终答案是

\[\prod_{i=1}^n 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的更多相关文章

  1. [LeetCode] Majority Element II 求众数之二

    Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorit ...

  2. [LeetCode] Majority Element 求众数

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  3. 【leetcode】Majority Element

    题目概述: Given an array of size n, find the majority element. The majority element is the element that ...

  4. [LintCode] Majority Number 求众数

    Given an array of integers, the majority number is the number that occurs more than half of the size ...

  5. ✡ leetcode 169. Majority Element 求出现次数最多的数 --------- java

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  6. (Array)169. Majority Element

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  7. LeetCode 169. Majority Element

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  8. [UCSD白板题] Majority Element

    Problem Introduction An element of a sequence of length \(n\) is called a majority element if it app ...

  9. 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 ...

  10. Majority Number I & || && |||

    Majority Number Given an array of integers, the majority number is the number that occurs more than ...

随机推荐

  1. zabbix 4.0修改页面LOGO

    基本页面展示 一.Logo icon-sprite.svg是一个集合的图片,logo和一级菜单栏里面的图标是在这上面平移得到的 第一种方法 1.  zabbix安装好以后的默认LOGO如下: 2.   ...

  2. el-submenu 设定title不显示

    原因为 插槽中有空格 slot=" title" 修改为 slot="title"即可

  3. 6.13API接口服务类漏洞探针

    ip地址解析:www.x.x.x.com, 对应网站目录为d:/wwwroot/xiaodi/ 而127.x.x.x,对应网站目录为d:/wwwroot/,可能存在网站备份文件zip,所以ip网址端口 ...

  4. 蓝桥杯-全球变暖 (DFS)

    你有一张某海域NxN像素的照片,"."表示海洋."#"表示陆地,如下所示: ....... .##.... .##.... ....##. ..####. .. ...

  5. Go runtime 调度器精讲(十):异步抢占

    原创文章,欢迎转载,转载请注明出处,谢谢. 0. 前言 前面介绍了运行时间过长和系统调用引起的抢占,它们都属于协作式抢占.本讲会介绍基于信号的真抢占式调度. 在介绍真抢占式调度之前看下 Go 的两种抢 ...

  6. 揭秘最为知名的黑客工具之一: Netcat!适用安全测试、渗透测试、黑客攻击!

    在网络安全领域,黑客工具一直备受关注.它们既可以被用于攻击,也可以用于防御.本文将为大家揭秘一款知名的黑客工具: Netcat. 1.Netcat是什么? Netcat被誉为"网络的瑞士军刀 ...

  7. servlet一些笔记、详解

    一.什么是servlet? 处理请求和发送响应的过程是由一种叫做Servlet的程序来完成的,并且Servlet是为了解决实现动态页面而衍生的东西.理解这个的前提是了解一些http协议的东西,并且知道 ...

  8. SpringMVC——SSM整合-异常处理器

    异常处理器 出现异常的常见位置与常见诱因: 框架内部抛出的异常:因使用不合规导致 数据层抛出异常:因外部服务器故障导致(例如:服务器访问超时) 业务层抛出的异常:因业务逻辑书写错误导致(例如:遍历业务 ...

  9. softirq和hardirq中断亲和度

    /proc/interrupts 和 /proc/softirqs 两者是相互关联的,但它们各自记录的信息和作用有所不同,反映了硬中断和软中断的两个处理阶段. 两者的关系: 硬中断引发软中断: 硬中断 ...

  10. 墨天轮沙龙 | 亚马逊云科技李君:见微知著 - Serverless云原生数据库概览

    导读 以业务为导向的数据库需要满足现代化应用的需要,以 Serverless 数据库为代表,云数据库正在迅速发展成熟,并带来更好的可访问性和高可用性,还有高扩展性与可迁移性. [墨天轮数据库沙龙-Se ...