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. 【YashanDB知识库】yasdb jdbc驱动集成BeetISQL中间件,业务(java)报autoAssignKey failure异常

    问题现象 BeetISQL中间件版本:2.13.8.RELEASE 客户在调用BeetISQL提供的api向yashandb的表中执行batch insert并将返回sequence设置到传入的jav ...

  2. 语音识别 可以跑在MCU上吗

    Ref: https://developer.arm.com/Additional%20Resources/Video%20Tutorials/AITechTalk-Video-Speech%20re ...

  3. 声明式 Shadow DOM:简化 Web 组件开发的新工具

    在现代 Web 开发中,Web 组件已经成为创建模块化.可复用 UI 组件的标准工具.而 Shadow DOM 是 Web 组件技术的核心部分,它允许开发人员封装组件的内部结构和样式,避免组件的样式和 ...

  4. MOGA-Net: 多目标遗传算法求解复杂网络中的社区《A Multiobjective Genetic Algorithm to Find Communities in Complex Networks》(遗传算法、多目标优化算法、帕累托最优)

    论文:A Multiobjective Genetic Algorithm to Find Communities in Complex Networks GitHub: IEEE 2012的论文. ...

  5. Angular 18+ 高级教程 – Prettier, ESLint, Stylelint

    前言 不熟悉 Prettier, ESLint, Stylelint 的朋友可以先看这篇 工具 – Prettier.ESLint.Stylelint. 首先,Angular 没有 built-in ...

  6. ASP.NET Core – HttpClient

    前言 以前写过的文章 Asp.net core 学习笔记 ( HttpClient ). 其实 HttpClient 内容是挺多的, 但是我自己用到的很少. 所以这篇记入一下自己用到的就好了. 参考 ...

  7. LeetCode题集-4 - 寻找两个有序数组的中位数,图文并茂,六种解法,万字讲解

    题目:给定两个大小分别为 m 和 n 的正序(从小到大)数组 nums1 和 nums2.请你找出并返回这两个正序数组的 中位数 . 算法的时间复杂度应该为 O(log (m+n)) . 作为目前遇到 ...

  8. 伯克利函数调用排行榜(BFCL)

    自 2022 年底以来,大语言模型(LLMs)凭借其执行通用任务的强大能力,成为众人关注的焦点.不仅限于聊天应用,将这些模型应用于开发各类 AI 应用和软件(如 Langchain, Llama In ...

  9. 28. 找出字符串中第一个匹配项的下标 Golang实现

    题目描述: 给你两个字符串 haystack 和 needle ,请你在 haystack 字符串中找出 needle 字符串的第一个匹配项的下标(下标从 0 开始).如果 needle 不是 hay ...

  10. 2024年7月中国数据库排行榜:PolarDB独领云风骚,达梦跨越新巅峰

    在7月发布的中国数据库流行度排行榜中,各大国产数据库厂商在不同领域表现势如破竹,PolarDB以800分刷新记录,并在SIGMOD 2024上获得"最佳论文奖":OceanBase ...