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. 我的 PowerShell 配置

    安装 Scoop: Scoop 是 Windows 上的包管理器 Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUse ...

  2. Windows 查看当前登录用户名

    使用 PowerShell 输入 whoami,PowerShell 将以 hostname\username 的方式输出主机名和用户名: $ whoami hostname\username 使用 ...

  3. 一分钟搭建Ghost个人网站博客系统

    什么是Ghost博客系统 Ghost 是一款设计简约.主题精致的个人博客系统,Ghost支持多用户创建和编辑,支持Markdown格式撰写文章,编辑的内容可即时预览. 创建轻量云主机 这里默认你已经有 ...

  4. 技术教程 —— 如何利用 SEI 实现音画同步?

    ​  摘要:利用 SEI 解决数据流录制回放过程中的音画不同步问题. 文|即构 Web SDK 开发团队 今年 6 月, ZEGO 即构科技推出了行业内首套数据流录制 PaaS 方案,打破传统录制服务 ...

  5. JAVA基础之5-函数式接口的实现

    之所以单独把这个列出来,是因为本人被一个源码给震撼了. 所以,本人目的是看看这个震撼实现,并模仿,最后把常规的实现也贴上,让读者可以看到相对完整的实现 注:本文代码基于JDK17 一.让人震撼的代码 ...

  6. CMake构建学习笔记16-使用VS进行CMake项目的开发

    目录 1. 概论 2. 详论 2.1 创建工程 2.2 加载工程 2.3 配置文件 2.4 工程配置 2.5 调试执行 3. 项目案例 4. 总结 1. 概论 在之前的系列博文中,我们学习了如何构建第 ...

  7. 从零开始搭建一个LoRaWAN基站

    先说两句 SX1301/SX1302是semtech公司推出的基站端射频基带芯片,其与SX127x/SX126x的主要区别在于: 只是个基带芯片,使用时需要加射频前端(SX125x/SAW/...) ...

  8. 记录一次BOOST库相关的使用包含互斥量、条件变量的类,引发的编译报错

    1. 工作中的代码: 2. 使用指针作为形参,不会造成编译报错,我是可以理解的. 那么请讨论下为什么使用值传递和引用作为形参,会造成编译报错? 3. 答案揭晓 boost 的mutex源码: 最终原因 ...

  9. Kubernetes Pod生命周期(十七)

    前面我们已经了解了 Pod 的设计原理,接下来我们来了解下 Pod 的生命周期.下图展示了一个 Pod 的完整生命周期过程,其中包含 Init Container.Pod Hook.健康检查 三个主要 ...

  10. 智慧矿山IT智能运维自动化解决方案

    矿山企业是国民经济中的重要组成部分,其资源开发和产业链条中涉及的环节与过程非常繁琐和复杂.随着我国矿山企业规模逐年扩大,为了提高其生产效率和降低其生产成本,信息化.数字化建设成为当下矿山企业发展的重要 ...