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 ...
随机推荐
- 玄机蓝队靶场_应急响应_01:linux日志分析
个人感觉这个靶场主要考验对linux的命令的基础掌握,对日志路径的基本了解. 一:解题 (1)ssh连接靶场,先用命令lsb_release -a看看是什么系统.然后发现是Debian GNU/Lin ...
- 以Top-Down思维去解决问题——递归
目录 递归的基础 递归的底层实现(不是重点) 递归的应用场景 编程中 两种解决问题的思维 自下而上(Bottom-Up) 自上而下(Top-Down) 自上而下的思考过程--求和案例 台阶问题 案例 ...
- 小tips:CSS实现0.5px的边框的两种方式
方式一 <style> .border { width: 200px; height: 200px; position: relative; } .border::before { con ...
- CSS – Transition & Animation
前言 之前的笔记 CSS – W3Schools 学习笔记 (3) 就有讲过 CSS Transitions 和 CSS Animations. 这里做一个整理, 补上一些细节. Transition ...
- SpringBoot——项目快速启动
SpringBoot项目快速启动 对SpringBoot项目打包(执行Maven构建指令package) 执行后会生成对应的项目 jar包,在文件夹找到该文件 在对应文件夹下即可执行 j ...
- SimpleRAG-v1.0.3:增加文件对话功能
Kimi上有一个功能,就是增加文件之后对话,比如我有如下一个私有文档: 会议主题:<如何使用C#提升工作效率> 参会人员:张三.李四.王五 时间:2024.9.26 14:00-16:00 ...
- JSP+Java编程资源
<JSP+Servlet+Tomcat应用开发从零开始学(第2版)>源码课件视频下载地址: https://pan.baidu.com/s/1HkFRul3wYBxe-skXCoQPwg ...
- seaborn.lmplot详解
官方文档 首先我们要知道,lmplot是用来绘制回归图的. 让我们来看看他的API: seaborn.lmplot(x, y, data, hue=None, col=None, row=None, ...
- Java日期时间API系列20-----Jdk8中java.time包中的新的日期时间API类,ZoneId时区ID大全等。
Java日期时间API系列19-----Jdk8中java.time包中的新的日期时间API类,ZonedDateTime与ZoneId和LocalDateTime的关系,ZonedDateTime格 ...
- 基于 Nginx 的大型互联网集群架构与实战方案
1. Nginx 负载均衡基础配置 首先,搭建一个基础的 Nginx 负载均衡器,用于将流量分发到多个后端服务器上. 步骤 1.1:安装 Nginx 在每台要作为负载均衡器的服务器上,安装 Nginx ...