Codeforces 1278F: Cards
题目传送门:CF1278F。
题意简述:
有 \(n\) 个独立随机变量 \(x_i\),每个随机变量都有 \(p = 1/m\) 的概率取 \(1\),有 \((1-p)\) 的概率取 \(0\)。
令 \(\displaystyle \Sigma x = \sum_{i=1}^{n} x_i\),求 \(E({(\Sigma x)}^k)\)。
题解:
\]
通常幂转下降幂是常用套路。注意这个恒等式:\(\displaystyle \binom{n}{i} i^{\underline{j}} = \binom{n-j}{i-j} n^{\underline{j}}\)。
下面是代码,时间复杂度为 \(\mathcal O (k^2)\):
#include <cstdio>
typedef long long LL;
const int Mod = 998244353;
const int MK = 5005;
inline int qPow(int b, int e) {
int a = 1;
for (; e; e >>= 1, b = (LL)b * b % Mod)
if (e & 1) a = (LL)a * b % Mod;
return a;
}
int N, M, K;
int S[MK][MK], Ans;
int main() {
scanf("%d%d%d", &N, &M, &K);
M = qPow(M, Mod - 2);
S[0][0] = 1;
for (int i = 1; i <= K; ++i)
for (int j = 1; j <= i; ++j)
S[i][j] = (S[i - 1][j - 1] + (LL)j * S[i - 1][j]) % Mod;
for (int i = 1, C = 1; i <= K; ++i)
C = (LL)C * (N - i + 1) % Mod * M % Mod,
Ans = (Ans + (LL)S[K][i] * C) % Mod;
printf("%d\n", Ans);
return 0;
}
Codeforces 1278F: Cards的更多相关文章
- codeforces 1278F - Cards(第二类斯特林数+二项式)
传送门 解题过程: \(答案=\sum^n_{i=0}*C^i_n*{\frac{1}{m}}^i*{\frac{m-1}{m}}^{n-i}*i^k\) 根据第二类斯特林数的性质\(n^k=\sum ...
- Codeforces 626B Cards(模拟+规律)
B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...
- Codeforces 999F Cards and Joy(二维DP)
题目链接:http://codeforces.com/problemset/problem/999/F 题目大意:有n个人,n*k张卡牌,每个人会发到k张卡牌,每个人都有一种喜欢的卡牌f[i],当一个 ...
- Codeforces 830B - Cards Sorting 树状数组
B. Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- codeforces #364a Cards
cf的a题没什么好说到,100的量级,每个人给2张牌,使每个人手中的牌点数相等.保证有一种分配方案. 对每个人,先计算出手中的牌的点数,然后循环两遍拿牌就可以. A. Cards time lim ...
- Codeforces 701A. Cards(水)
A. Cards time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- CodeForces 701A Cards
直接看示例输入输出+提示 1. 统计所有数的和 sum,然后求 sum/(n/2) 的到一半数的平均值 6 1 5 7 4 4 3 ->1+5+7+4+4+3=24 分成3组 每组值为8 in ...
- CodeForces 626B Cards
瞎搞题...凭直觉+猜测写了一发,居然AC了.. #include<cstdio> #include<cstring> #include<cmath> #inclu ...
- CodeForces 830B - Cards Sorting
将每个数字的位置存进该数字的vector中 原数组排个序从小到大处理,每次在vector里二分找到距离当前位置“最远”的位置(相差最大),更新答案 树状数组维护每个数字现在的位置和原位置之差 #inc ...
随机推荐
- vlmcsd
scp ./vlmcsd-x64-musl-static xxx@host.ip:/opt/kms/ chmod u+x /opt/kms/vlmcsd-x64-musl-static ./vlmcs ...
- web-never give up
打开题目连接 ?id=1 ,疑是注入点 但是输入其他数字无果 打开源码,发现注释有网页链接 打开连接123.206.87.240:8006/test/1p.html 发现回到了bugku的论坛首页,应 ...
- zz《可伸缩服务架构 框架与中间件》综合
第1章 如何设计一款永不重复的高性能分布式发号器 1. 为什么不直接采用UUID? 虽然UUID能够保证唯一性,但无法满足业务系统需要的很多其他特性,比如时间粗略有序性.可反解和可制造性(说人话,就是 ...
- echarts使用------地图生成----省市地图的生成及其他相关细节调整
为使用多种业务场景,百度echarts地图示例只有中国地图,那么在使用省市地图的时候,就需要我们使用省市的地图数据了 以下为陕西西安市的地图示例: 此页面引用echarts的js:http://ech ...
- rabbitmq 添加用户
参考博客 https://www.rabbitmq.com/access-control.html rabbitmqctl add_user admin admin rabbitmqctl set_p ...
- CF-weekly4 F. Kyoya and Colored Balls
https://codeforces.com/gym/253910/problem/F F. Kyoya and Colored Balls time limit per test 2 seconds ...
- hdu 6495 dp
http://acm.hdu.edu.cn/showproblem.php?pid=6495 题意 有n个挑战(1e3),假如接受,在挑战之前体力x会变成min(x,\(b[i]\)),然后会减去a[ ...
- pycharm配置docker
- JavaScript查找两个数组的相同元素和相差元素
let intersection = a.filter(v => b.includes(v)) 返回交集数组 let difference = a.concat(b).filter(v => ...
- pymysql的基本使用
序pymysql的语法sql注入问题数据的增删查改 TOC 序 当我们在写程序中需要使用到数据库的时候,尽量在代码层次实现一些限制,例如两张表,我们不再使用外键去关联表与表之间的关系,我们可以在程序层 ...