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 ...
随机推荐
- div设置overflow-scroll滚动之后,jq获取其子元素的offset.top出现问题。
先上个图: 布局很简单,左右超过屏幕的部分自行滚动. 1. html <div class="ce-container"> <div class="ce ...
- LightGBM 调参方法(具体操作)
sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003& ...
- linux下安装SlickEdit
title: linux下安装SlickEdit tags: 软件 date: 2018-10-08 21:32:12 --- linux下安装SlickEdit 下载安装包和补丁文件 补丁文件 官方 ...
- Ubuntu编译Protobuf(Base tensorflow-12)报错
报错1: dogepool@ubuntu-server:~/dogecoin$ ./autogen.sh./autogen.sh: 50: ./autogen.sh: autoreconf: not ...
- 01--STL算法(算法基础)
一:算法概述 算法部分主要由头文件<algorithm>,<numeric>和<functional>组成. <algorithm>是所有STL头文件中 ...
- python 包和模块间的引入
##############################总结####################### 主要内容: 1. 模块 2. import 3. from xxx import xxx ...
- 利用css3给座右铭设置漂亮的渐变色
.footer-container .footer-content p .motto { font-weight: bolder; -webkit-background-clip: text; -we ...
- 清理sql2012数据库日志
--1.先把数据库设置为简单模式(右击数据库名->点'属性'->点'选项'->恢复模式改成'简单'->点'确定'按钮,--2.再执行下面的语句(或者右击数据库点'任务'-> ...
- GeoGlobe Server运维
本篇博文简单记录鄙人在管理和维护GeoGlobe Server中,遇到的一些问题以及可行的解决方案 1 关于启动内存 Server默认的启动内存是256M,当服务比较多的时候,启动就会很慢.我们可以修 ...
- ueditor 百度编辑器图片上传 接 node.js 及一些前端自定义
百度编辑器 用node.js 做服务端 demo 大神已整理的 记录一下 以作参考 https://github.com/netpi/ueditor 1. 前端图片工具栏上传input file在这里 ...