题目传送门:CF1278F

题意简述:

有 \(n\) 个独立随机变量 \(x_i\),每个随机变量都有 \(p = 1/m\) 的概率取 \(1\),有 \((1-p)\) 的概率取 \(0\)。

令 \(\displaystyle \Sigma x = \sum_{i=1}^{n} x_i\),求 \(E({(\Sigma x)}^k)\)。

题解:

\[\begin{aligned} \mathbf{Ans} &= \sum_{i=0}^{n} \binom{n}{i} p^i (1-p)^{n-i} i^k \\ &= \sum_{i=0}^{n} \binom{n}{i} p^i (1-p)^{n-i} \sum_{j=0}^{k} {k \brace j} i^{\underline{j}} \\ &= \sum_{j=0}^{k} {k \brace j} \sum_{i=0}^{n} \binom{n}{i} p^i (1-p)^{n-i} i^{\underline{j}} \\ &= \sum_{j=0}^{k} {k \brace j} n^{\underline{j}} \sum_{i=0}^{n} \binom{n-j}{i-j} p^i (1-p)^{n-i} \\ &= \sum_{j=0}^{k} {k \brace j} n^{\underline{j}} p^j \sum_{i=0}^{n-j} \binom{n-j}{i} p^i (1-p)^{n-j-i} \\ &= \sum_{j=0}^{k} {k \brace j} n^{\underline{j}} p^j \end{aligned}
\]

通常幂转下降幂是常用套路。注意这个恒等式:\(\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的更多相关文章

  1. 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 ...

  2. Codeforces 626B Cards(模拟+规律)

    B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...

  3. Codeforces 999F Cards and Joy(二维DP)

    题目链接:http://codeforces.com/problemset/problem/999/F 题目大意:有n个人,n*k张卡牌,每个人会发到k张卡牌,每个人都有一种喜欢的卡牌f[i],当一个 ...

  4. Codeforces 830B - Cards Sorting 树状数组

    B. Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  5. codeforces #364a Cards

    cf的a题没什么好说到,100的量级,每个人给2张牌,使每个人手中的牌点数相等.保证有一种分配方案. 对每个人,先计算出手中的牌的点数,然后循环两遍拿牌就可以.   A. Cards time lim ...

  6. Codeforces 701A. Cards(水)

    A. Cards time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  7. 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 ...

  8. CodeForces 626B Cards

    瞎搞题...凭直觉+猜测写了一发,居然AC了.. #include<cstdio> #include<cstring> #include<cmath> #inclu ...

  9. CodeForces 830B - Cards Sorting

    将每个数字的位置存进该数字的vector中 原数组排个序从小到大处理,每次在vector里二分找到距离当前位置“最远”的位置(相差最大),更新答案 树状数组维护每个数字现在的位置和原位置之差 #inc ...

随机推荐

  1. ffmpeg下载m3u8流媒体

    安装 编译好的windows可用版本的下载地址(官网中可以连接到这个网站,和官方网站保持同步): http://ffmpeg.zeranoe.com/builds/ 该版本为FFMPEG的Static ...

  2. mysql 日期处理函数

    首先创建一张实验用的一张表 drop table if exists t_student; create table t_student( id int primary key auto_increm ...

  3. LeetCode 674. Longest Continuous Increasing Subsequence最长连续递增序列 (C++/Java)

    题目: Given an unsorted array of integers, find the length of longest continuous increasing subsequenc ...

  4. 【[POI2012]TOU-Tour de Byteotia】

    [[POI2012]TOU-Tour de Byteotia] 洛谷P3535 https://www.luogu.org/problemnew/show/P3535 JDOJ 2193旅游景点(同类 ...

  5. angular的Hash 模式和 HTML 5 模式

    去除地址 # ,将{ provide: LocationStrategy, useClass: HashLocationStrategy }改为 { provide: LocationStrategy ...

  6. glade No package 'libxml-2.0' found

    ------------恢复内容开始------------ 今天突发奇想 root@Aja:~/下载/libxml2-master# glade 不会用纳 百度一下——————————>> ...

  7. 大话设计模式Python实现-模板方法模式

    模板方法模式(Template Method Pattern):定义一个操作中的算法骨架,将一些步骤延迟至子类中.模板方法使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤. 下面是一个模 ...

  8. linux 用du查看硬盘信息

    linux 用du查看硬盘信息 <pre>[root@iZ238qupob7Z web]# df -hFilesystem Size Used Avail Use% Mounted on/ ...

  9. LeetCode 231.2的幂

    LeetCode 231.2的幂 题目: 给定一个整数,编写一个函数来判断它是否是 2 的幂次方. 算法: 若一个数是2的幂次的话定会有n & (n - 1) == 0这个关系成立 所以直接用 ...

  10. springboot学习源码

    springbootTest 学习源码链接 启动前,需要创建数据库表,修改自己的链接配置 create database test01; use test01; CREATE TABLE catego ...