[CodeForces]908D New Year and Arbitrary Arrangement
设状态f[i][j]表示有i个a,j个ab的期望
发现如果i+j>=k的话就再来一个b就行了。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int mod=1e9++;
int k,pa,pb,inva,invb,f[][];
int ksm(int d,int z) {
int res=;
while(z) {
if(z&) res=(1ll*res*d)%mod;
d=(1ll*d*d)%mod;
z>>=;
}
return res;
}
int main() {
scanf("%d%d%d",&k,&pa,&pb);
int tp=ksm(pa+pb,mod-);
pa=1ll*pa*tp%mod,pb=1ll*pb*tp%mod;
invb=ksm(pb,mod-);
for(int i=k;i;i--) {
for(int j=k;~j;j--) {
if(i+j>=k) {f[i][j]=(1ll*i+1ll*j+1ll*pa*invb)%mod;continue;}
f[i][j]=(1ll*f[i+][j]*pa+1ll*f[i][j+i]*pb)%mod;
}
}
cout<<f[][];
return ;
}
New Year and Arbitrary Arrangement
[CodeForces]908D New Year and Arbitrary Arrangement的更多相关文章
- Codeforces 908D New Year and Arbitrary Arrangement(概率DP,边界条件处理)
题目链接 Goodbye 2017 Problem D 题意 一个字符串开始,每次有$\frac{pa}{pa+pb}$的概率在后面加一个a,$\frac{pb}{pa+pb}$的概率在后面加一个 ...
- CF 908D New Year and Arbitrary Arrangement——期望dp
题目:http://codeforces.com/contest/908/problem/D 注意是子序列.加一个a对ab个数无影响:加一个b使ab个数多出它前面的a那么多个.所以状态里记录有多少个a ...
- 908D New Year and Arbitrary Arrangement
传送门 分析 代码 #include<iostream> #include<cstdio> #include<cstring> #include<string ...
- Solution -「CF 908D」New Year&Arbitrary Arrangement
\(\mathcal{Description}\) Link. 给定 \(n,p_a,p_b\),初始有一个空串,每次操作有 \(\frac{p_a}{p_a+p_b}\) 的概率在其后添加字 ...
- Codeforces 908 D.New Year and Arbitrary Arrangement (概率&期望DP)
题目链接:New Year and Arbitrary Arrangement 题意: 有一个ab字符串,初始为空. 用Pa/(Pa+Pb)的概率在末尾添加字母a,有 Pb/(Pa+Pb)的概率在末尾 ...
- 【CodeForces】908 D. New Year and Arbitrary Arrangement
[题目]Good Bye 2017 D. New Year and Arbitrary Arrangement [题意]给定正整数k,pa,pb,初始有空字符串,每次有pa/(pa+pb)的可能在字符 ...
- Codeforces New Year and Arbitrary Arrangement
New Year and Arbitrary Arrangement time limit per test2 seconds You are given three integers k, pa a ...
- Codeforces 908 D New Year and Arbitrary Arrangement
Discription You are given three integers k, pa and pb. You will construct a sequence with the follow ...
- CF 908 D New Year and Arbitrary Arrangement —— 期望DP
题目:http://codeforces.com/contest/908/problem/D 首先,设 f[i][j] 表示有 i 个 a,j 个 ab 组合的期望,A = pa / (pa + pb ...
随机推荐
- HDU 5538/ 2015长春区域 L.House Building 水题
题意:求给出图的表面积,不包括底面 #include<bits/stdc++.h> using namespace std ; typedef long long ll; #define ...
- oc28--Property增强
// // Person.h #import <Foundation/Foundation.h> @interface Person : NSObject /* { @public int ...
- 2749: [HAOI2012]外星人
首先像我一样把柿子画出来或者看下hint 你就会发现其实是多了个p-1这样的东东 然后除非是2他们都是偶数,而2就直接到0了 算一下2出现的次数就好 #include<cstdio> #i ...
- [BZOJ 1741] Asteroids
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1741 [算法] 将每颗小行星的行,列相连,问题就转化为了求这张图的最小覆盖 由kon ...
- web动画小结
前端写动画,无非两种方案,一种是通过css,另一种是js css的方案: 1.transform的单独使用 (IE9+) rotate(90deg) 2d旋转,也可以理解为沿着3D的Z轴旋转 rota ...
- LeetCode.884-两句话中不常见的单词(Uncommon Words from Two Sentences)
这是悦乐书的第338次更新,第362篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第207题(顺位题号是884).我们给出了两个句子A和B.(一个句子是一串空格分隔的单词 ...
- Python简介和基础入门
1.1 Python是什么 相信混迹IT界的很多朋友都知道,Python是近年来最火的一个热点,没有之一.从性质上来讲它和我们熟知的C.java.php等没有什么本质的区别,也是一种开发语言,而且已经 ...
- ACM_买粽子(UVA唯一的雪花)
买粽子 Time Limit: 2000/1000ms (Java/Others) Problem Description: 端午节快到了,小蛋准备到集市上买粽子.于是周六这天,小蛋和舍友搭着公交到了 ...
- 【Codeforces】Codeforces Round #373 (Div. 2) -C
C. Efim and Strange Grade Efim just received his grade for the last test. He studies in a special sc ...
- windows phone数据网络开发
LINQ LINQ的全称是Language INtegrated Query,即语言集成查询.LINQ是一种查询语言,不仅可以对数字库进行查询,还可以对.net的数据集.数组.Xml文档等对象进行查询 ...