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. Windows 不小心把管理员帐户弄没了怎么办

    今天折腾不小心把管理员帐号的权限给改没了,重启之后很多操作做不了.解决方法如下: Windows + R 打开运行,或者打开资源管理器,输入 control userpasswords2 命令打开用户 ...

  2. Node.js 使用

    创建 Node 项目 npm init -y # 初始化 Node 项目 package.json 文件 这个文件记录了项目的相关信息. { "name": "hello ...

  3. 利用水墨映客图床作为COS服务器

    目录 利用水墨映客作为COS服务器 利用picGo配合typora上传图片 安装PicGo(以Windows为例) 安装lankong插件 在SpringBoot中开发图片上传工具类 设置图片上传请求 ...

  4. 注册中心Nacos集群搭建

    一提到注册中心,大家往往想到Zookeeper.或者Eureka.今天我们看看阿里的一款配置中心+注册中心的中间件--Nacos.有了它以后,我们的项目中的配置就可以统一从Nacos中获取了,而且Sp ...

  5. 小tips:前端容易读错的单词列表

    排名第一的是width,音标/wɪdθ/,发/i/的音,不是发/ai/的音: hidden音标/ˈhɪdn/发/i/的音,不是发/ai/的音: hide音标/haɪd/,发/ai/的音: float音 ...

  6. QT6框架也能开发Web浏览器应用程序:QT6框架如何编译运行测试WebAssembly应用程序?

    QT6框架也能开发Web浏览器应用程序:QT6框架如何编译运行测试WebAssembly应用程序? 简介 本文将介绍如何使用QT6框架开发Web浏览器应用程序,并介绍具体的编译运行测试WebAssem ...

  7. 大一下的acm生活

    在一个名气不大的211学校刷题的日常. 感觉这些算法题好难啊! 最近有好多实验室要招新,不知道该怎么办,自己只想就业,并不想升学,好烦! 真枯燥,好无聊. 现在要学习相关的网页设计和网站建设,例如配色 ...

  8. pytorch中LSTM各参数理解

    nn.LSTM(input_dim,hidden_dim,nums_layer,batch_first) 各参数理解: input_dim:输入的张量维度,表示自变量特征数 hidden_dim:输出 ...

  9. [TK] HH的项链 离线树状数组解法

    实际上这题很难和树状数组联系起来,我感觉效率也不是很高,感觉不是正解 怎么使用树状数组 这道题我们很容易想到一点:同种物品在一个区间内只能出现一次,先不考虑别的问题,我们想出下面这种使用树状数组的思路 ...

  10. 全网最适合入门的面向对象编程教程:54 Python字符串与序列化-字符串格式化与format方法

    全网最适合入门的面向对象编程教程:54 Python 字符串与序列化-字符串格式化与 format 方法 摘要: 在 Python 中,字符串格式化是将变量插入到字符串中的一种方式,Python 提供 ...