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 ...
随机推荐
- 解决docker多开mysql报错问题
1.vim /etc/sysctl.conf fs.aio-max-nr=262144 重新加载 sysctl -p /etc/sysctl.conf
- hibernate的学习周
Hibernate核心:ORM(对象关系映射) BeginSession关闭的时候要session.close(),而getCurrentsession不需要,它会自动关闭 Session.load( ...
- Spring Cloud构建微服务架构(六)高可用服务注册中心
http://blog.didispace.com/springcloud6/ https://www.jianshu.com/p/df9393755a05 http://www.ityouknow. ...
- python 正则表达式re模块
#####################总结############## 优点: 灵活, 功能性强, 逻辑性强. 缺点: 上手难,旦上手, 会爱上这个东西 ...
- python 变量 if
#########################总结###################### 1. 初识python python是一门弱类型的解释型高级编程语言 解释器: CPython 官方 ...
- EL表达式获取日期时间类型后格式化的问题
最近在项目中遇到的问题,就是从后台取到的java.util.Date类型的数据,在前台需要格式化的问题. 开始想了很多办法,其实在JSP页面中处理很简单,JSTL提供的format标签即可解决这个问题 ...
- Ubuntu18.04 关闭和开启图形界面
关闭用户图形界面,使用tty登录. sudo systemctl set-default multi-user.target sudo reboot 开启用户图形界面. sudo systemctl ...
- spring boot集成redis的血泪史
首先说明环境不是我搭建的,然后因项目需要添加redis的时候,麻烦来了.springboot 用的是1.5.9因为以前弄过redis,所以直接拿过来,麻烦了首先是莫名的错误,连项目都启动不了.但是最后 ...
- Can't read swagger JSON from http://localhost:8080/Test/api-docs
新手入坑Swagger,搜了下网上博客,各种整合费时费力.弄出来竟然报错: Can't read swagger JSON from http://localhost:8080/Test/api-do ...
- @CrossOrigin注解与跨域访问
在Controller中看到@CrossOrigin ,这是什么?有什么用?为什么要用? what? @CrossOrigin是用来处理跨域请求的注解 先来说一下什么是跨域: (站在巨人的肩膀上) 跨 ...