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. String真的不可变吗?

    Java中的String是不可变对象 在面向对象及函数编程语言中,不可变对象(英语:Immutable object)是一种对象,在被创造之后,它的状态就不可以被改变.至于状态可以被改变的对象,则被称 ...

  2. SLF4J+Logback日志搭建

    一.jar包依赖 <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api< ...

  3. .net framework创建Nuget包简要教程

    前言 nuget包生成在.net framework和.net core/.net standard下的是不同的. .net framework中稍微复杂些,下面记录了我自己在.net framewo ...

  4. WPF 如何利用Blend给Button添加波纹效果

    先看一下效果吧: 如果不会写动画或者懒得写动画,就直接交给Blend来做吧; 其实Blend操作起来很简单,有点类似于在操作PS,我们只需要设置关键帧,鼠标点来点去就可以了,Blend会自动帮我们生成 ...

  5. Java 读取 IP 地址

    使用 InetAddress 类 可以利用 Java 自带的 InetAddress 类来检查一个字符串是否为有效的 IP 地址: import java.net.InetAddress; // 导入 ...

  6. [golang]查询ssl证书剩余有效天数并邮件提醒

    前言 自从云厂商的免费ssl证书改成3个月,而且证书数量还是20个之后,自己网站的ssl证书就换成了其它免费方案.但是免费方案不会提醒证书过期,所以写个工具每天定时查询证书剩余有效天数,如果证书即将过 ...

  7. SimCLR: 一种视觉表征对比学习的简单框架《A Simple Framework for Contrastive Learning of Visual Representations》(对比学习、数据增强算子组合,二次增强、投影头、实验细节很nice),好文章,值得反复看

    现在是2024年5月18日,好久没好好地看论文了,最近在学在写代码+各种乱七八糟的事情,感觉要和学术前沿脱轨了(虽然本身也没在轨道上,太菜了),今天把师兄推荐的一个框架的论文看看(视觉CV领域的). ...

  8. TypeScript 高级教程 – 把 TypeScript 当编程语言使用 (第二篇)

    前言 上一篇, 我们提到, TypeScript 进阶有 3 个阶段. 第一阶段是 "把 TypeScript 当强类型语言使用", 我们已经介绍完了. 第二阶段是 "把 ...

  9. ASP.NET Core – Static Files

    前言 记入一些冷门的知识. Custom content-type var fileExtensionContentTypeProvider = new FileExtensionContentTyp ...

  10. 使用 fabric.js 开发移动端 H5 图片编辑器

    大家好,我是开源图片编辑器的 https://github.com/ikuaitu/vue-fabric-editor 的作者,它是一款基于 PC 版本的开源图片编辑器. 最近很多开发者咨询,是否可以 ...