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 ...
随机推荐
- 使用响应的json数据判断订单查询是否成功;
#查询中通快递import requestsrr=requests.session()headers={"User-Agent": "Mozilla/5.0 (Windo ...
- Pwnable-bof
Download : http://pwnable.kr/bin/bof Download : http://pwnable.kr/bin/bof.c 下载之后,先看看c源码 #include < ...
- luoguP4069 [SDOI2016]游戏
题意 显然书剖套李超树. 考虑怎么算函数值: 设\((x,y)\)的\(lca\)为\(z\),我们插一条斜率为\(k\),截距为\(b\)的线段. \((x,z)\)上的点\(u\): \(f(u) ...
- Django 模版语言
传入变量 {{ 变量名 }} 在 view.py 的函数返回 render 时在html文件名后传入一个字典,字典的 key 对应html文件中的变量名,value 为传入的值 views.py: d ...
- celery分布式任务队列的使用
一.Celery介绍和基本使用 Celery 是一个 基于python开发的分布式异步消息任务队列,通过它可以轻松的实现任务的异步处理, 如果你的业务场景中需要用到异步任务,就可以考虑使用celery ...
- ReverseInteger:实现int整数的反转
原文链接 Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 ...
- FFT/NTT基础题总结
在学各种数各种反演之前把以前做的$FFT$/$NTT$的题整理一遍 还请数论$dalao$口下留情 T1快速傅立叶之二 题目中要求求出 $c_k=\sum\limits_{i=k}^{n-1}a_i* ...
- 探索 ASP.Net Core 3.0系列三:ASP.Net Core 3.0中的Service provider validation
前言:在本文中,我将描述ASP.NET Core 3.0中新的“validate on build”功能. 这可以用来检测您的DI service provider是否配置错误. 具体而言,该功能可检 ...
- vue中toggle切换的3种写法
前言:查看下面代码,在任意编辑器中直接复制粘贴运行即可 1:非动态组件(全局注册2个组件,借用v-if指令和三元表达式) <!DOCTYPE html> <html> < ...
- python asyncio 使用ThreadPoolExecutor和asyncio完成阻塞IO请求
#使用多线程:在协程中集成阻塞io import asyncio from concurrent.futures import ThreadPoolExecutor import socket fro ...