CF1096E The Top Scorer
题目地址:洛谷CF1096E
本场AC数最少 (最难) 的题目
题目大意:给出三个数p , s,r,表示有p人,每个人都有一个非负得分,所有人的得分和为s,Hasan的得分至少为r,求Hasan是第一的概率(得分相同的人名次是等概率分布)
数据范围: \(1 \leq p \leq 100,0 \leq r \leq s \leq 5000\)
注意输出有一个整数化处理:若 \(ans = \frac{P}{Q}\) ,输出 \(P \times inv_Q(mod\ 998244353)\) ,这里的 \(inv_Q(mod\ 998244353)\) 指的是 \(Q\) 的模 \(998244353\) 的乘法逆元
容斥原理
首先解决一个问题:有 \(p\) 人,所有人的得分和为 \(s\) 且所有人的得分均小于等于 \(m\) ,有多少种情况?
根据容斥原理,答案为:
\[\sum_{i=0}^{p}\ (-1)^i\ C_{p}^{i}\ C_{s+p-1-i(m+1)}^{p-1}\]
有了这个公式,接下来就是好办了:枚举 Hasan 的得分和与 Hasan 得分相同的人数,算出每一种情况的总数之和,最后除以所有可能的情况即为 \(ans\)
代码:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 10006, M = 106, P = 998244353;
int jc[N], jcinv[N];
inline int ksm(int a, int b) {
int ans = 1;
while (b) {
if (b & 1) ans = (ll)ans * a % P;
a = (ll)a * a % P;
b >>= 1;
}
return ans;
}
inline int C(int b, int a) {
if (a == b) return 1;
if (a < 0 || a > b) return 0;
return (ll)jc[b] * jcinv[a] % P * jcinv[b-a] % P;
}
inline int g(int s, int p, int x) {
int ans = 0;
for (int i = 0; i <= p; i++)
ans = (ans + (ll)((i & 1) ? P - 1 : 1) * C(p, i) % P * C(s + p - 1 - i * (x + 1), p - 1) % P) % P;
return ans;
}
inline int inv(int x) {
return (ll)jc[x-1] * jcinv[x] % P;
}
int main() {
jc[0] = 1;
for (int i = 1; i <= 10000; i++)
jc[i] = (ll)jc[i-1] * i % P;
jcinv[10000] = ksm(jc[10000], P - 2);
for (int i = 10000; i; i--)
jcinv[i-1] = (ll)jcinv[i] * i % P;
int p, s, r;
cin >> p >> s >> r;
int ans = 0;
for (int i = r; i <= s; i++)
for (int j = 1; j <= p; j++)
ans = (ans + (ll)C(p - 1, j - 1) * inv(j) % P * g(s - i * j, p - j, i - 1) % P) % P;
cout << ((ll)ans * ksm(C(s - r + p - 1, p - 1), P - 2) % P + P) % P << endl;
return 0;
}
注意:本题代码中细节处理较为繁琐也很需要技巧,建议亲自动手实现
CF1096E The Top Scorer的更多相关文章
- CodeForces 1096E: The Top Scorer
一道经典组合数学+容斥题. 题目传送门:CF1096E. 题意简述: \(p\) 个人,每个人有得分 \(a_i\). 总得分 \(\sum a_i = s\). 第一个人得分 \(a_1 \ge r ...
- Codeforces.1096E.The Top Scorer(组合)
题目链接 感觉这题很裸啊,除了看着恶心点也没什么了,怎么过的人那么少.. \(Description\) 给定\(n,r,s\),表示有\(n\)个人,设每个人的得分是非负整数\(a_i\),已知第一 ...
- Codeforces Educational Codeforces Round 57 题解
传送门 Div 2的比赛,前四题还有那么多人过,应该是SB题,就不讲了. 这场比赛一堆计数题,很舒服.(虽然我没打) E. The Top Scorer 其实这题也不难,不知道为什么这么少人过. 考虑 ...
- 每日英语:A Chinese Soccer Club Has Won Something!
A 1-1 tie at home was sufficient for Guangzhou Evergrande to clinch the Asian Champions League title ...
- Educational Codeforces Round 57题解
A.Find Divisible 沙比题 显然l和2*l可以直接满足条件. 代码 #include<iostream> #include<cctype> #include< ...
- Codeforces Educational Round 57
这场出题人好像特别喜欢998244353,每个题里都放一个 A.Find Divisible 考察选手对输入输出的掌握 输出l 2*l即可(为啥你要放这个题,凑字数吗 #include<cstd ...
- Educational Codeforces Round 57 (Rated for Div. 2) ABCDEF题解
题目总链接:https://codeforces.com/contest/1096 A. Find Divisible 题意: 给出l,r,在[l,r]里面找两个数x,y,使得y%x==0,保证有解. ...
- ADO.NET一小记-select top 参数问题
异常处理汇总-后端系列 http://www.cnblogs.com/dunitian/p/4523006.html 最近使用ADO.NET的时候,发现select top @count xxxx 不 ...
- Configure a VLAN on top of a team with NetworkManager (nmcli) in RHEL7
SOLUTION VERIFIED September 13 2016 KB1248793 Environment Red Hat Enterprise Linux 7 NetworkManager ...
随机推荐
- day-03(js)
回顾: css: 层叠样式表 作用: 渲染页面 提供工作效率,将html和样式分离 和html的整合 方式1:内联样式表 通过标签的style属性 <xxx style="...&qu ...
- SVN提交前准备
操作步骤1: 操作步骤2: 操作步骤3: 操作步骤4: 操作步骤5: 操作步骤6:查看 操作步骤7:ignore 操作步骤8:直接提交项目
- Django中的ORM框架使用小技巧
Django中的ORM框架使用小技巧 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. Django对各个数据提供了很好的支持,包括PostgreSQL,MySQL,SQLite ...
- Xenserver之设置Xenserver和VM机开机自动启动
一.设置Xenserver开机自动启动 [root@xenserver-DS-TestServer09 ~]# xe pool-list uuid ( RO) : b1c803a6-88cf-7b24 ...
- JAVA核心技术I---JAVA基础知识(知识回顾)
一:多态问题 class Father { public void hello() { System.out.println("Father says hello."); } } ...
- 8.Hystrix-Feign配置服务降级
项目中用到Feign调用服务端方法并做服务降级处理 1.application.properties配置: feign.hystrix.enabled=true 2.pom: <!--feign ...
- 解析ArcGis的字段计算器(一)——数值型数据计算,从“面积计算”开始
先来点儿背景知识铺垫: ArcMap的字段计算器提供了两种脚本语言的支持用以计算,两种脚本语言是VBScript与Python. 多数人选择使用前者,因为它的基本函数和Excel的函数貌似一样.注意我 ...
- python S2-45 漏洞利用工具
初学python脚本,写个工具练练手.第一次写勿喷.呃...忘了截图了,补上了. 程序对于处理 JSON post 有些问题,其他地方还没发现有啥问题. #coding:utf-8 import ch ...
- storm+Calcite
敬请期待... http://blog.csdn.net/yu616568/article/details/49915577 https://github.com/terry-chelsea/bigd ...
- MySQL Errno : 1062 错误修复
网站突然出现如下错误: MySQL Error : Duplicate entry '1' for key 'views' MySQL Errno : 1062 Message : Duplicate ...