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 ...
随机推荐
- 蓝桥杯dfs搜索专题
2018激光样式 #include<bits/stdc++.h> using namespace std; /* dfs(i) 第i个激光机器 有两种选择:vis[i-1] == 0 时 ...
- python爬虫之深度爬取实例
写了一个之前没完成的项目,代码优化不够,速度有点慢,应该也有错误的地方,望大佬看了之后能给点建议......... 这是开始的url,先看一下它的网页结构:http://www.cymodel.net ...
- Requests text乱码
都在推荐用Requests库,而不是Urllib,但是读取网页的时候中文会出现乱码. 分析: r = requests.get(“http://www.baidu.com“) **r.text返回的是 ...
- CF-weekly4 D. Haar Features
https://codeforces.com/gym/253910/problem/D D. Haar Features time limit per test 1 second memory lim ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) C. p-binary 水题
C. p-binary Vasya will fancy any number as long as it is an integer power of two. Petya, on the othe ...
- [LOJ 2133][UOJ 131][BZOJ 4199][NOI 2015]品酒大会
[LOJ 2133][UOJ 131][BZOJ 4199][NOI 2015]品酒大会 题意 给定一个长度为 \(n\) 的字符串 \(s\), 对于所有 \(r\in[1,n]\) 求出 \(s\ ...
- vue_04 练习
目录 vue_项目初始: car.vue Nav.vue: cardata.vue vue_项目初始: 1.Home.vue页面组件显示基本信息:欢迎来到汽车系统 Car.vue页面组件,完成Cars ...
- 剑指offer:剪绳子(找规律,贪心算法,动态规划)
1. 题目描述 /* 题目描述 给你一根长度为n的绳子,请把绳子剪成m段(m.n都是整数,n>1并且m>1),每段绳子的长度记为k[0],k[1],...,k[m].请问k[0]xk[1] ...
- ssl与ssh
openssl genrsa -out private_key.pem 1024 ssh-keygen -t rsa -C zzf073@163.com ssl是安全会话协商机制: ssh是安全访问机 ...
- RabbitMQ系列(一)rabbitmq简介
------------恢复内容开始------------ 参考:https://www.cnblogs.com/vipstone/p/9275256.html RabbitMQ简介 在介绍Rabb ...