设状态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的更多相关文章

  1. Codeforces 908D New Year and Arbitrary Arrangement(概率DP,边界条件处理)

    题目链接  Goodbye 2017 Problem D 题意  一个字符串开始,每次有$\frac{pa}{pa+pb}$的概率在后面加一个a,$\frac{pb}{pa+pb}$的概率在后面加一个 ...

  2. CF 908D New Year and Arbitrary Arrangement——期望dp

    题目:http://codeforces.com/contest/908/problem/D 注意是子序列.加一个a对ab个数无影响:加一个b使ab个数多出它前面的a那么多个.所以状态里记录有多少个a ...

  3. 908D New Year and Arbitrary Arrangement

    传送门 分析 代码 #include<iostream> #include<cstdio> #include<cstring> #include<string ...

  4. Solution -「CF 908D」New Year&Arbitrary Arrangement

    \(\mathcal{Description}\)   Link.   给定 \(n,p_a,p_b\),初始有一个空串,每次操作有 \(\frac{p_a}{p_a+p_b}\) 的概率在其后添加字 ...

  5. Codeforces 908 D.New Year and Arbitrary Arrangement (概率&期望DP)

    题目链接:New Year and Arbitrary Arrangement 题意: 有一个ab字符串,初始为空. 用Pa/(Pa+Pb)的概率在末尾添加字母a,有 Pb/(Pa+Pb)的概率在末尾 ...

  6. 【CodeForces】908 D. New Year and Arbitrary Arrangement

    [题目]Good Bye 2017 D. New Year and Arbitrary Arrangement [题意]给定正整数k,pa,pb,初始有空字符串,每次有pa/(pa+pb)的可能在字符 ...

  7. Codeforces New Year and Arbitrary Arrangement

    New Year and Arbitrary Arrangement time limit per test2 seconds You are given three integers k, pa a ...

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

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

随机推荐

  1. 史上最全opencv源代码解读,opencv源代码具体解读文件夹

    本博原创,如有转载请注明本博网址http://blog.csdn.net/ding977921830/article/details/46799043. opencv源代码主要是基于adaboost算 ...

  2. vim快速操作

    简明 VIM 练级攻略 vim的学习曲线相当的大(参看各种文本编辑器的学习曲线),所以,如果你一开始看到的是一大堆VIM的命令分类,你一定会对这个编辑器失去兴趣的.下面的文章翻译自<Learn ...

  3. 4.非关系型数据库(Nosql)之mongodb:普通索引,唯一索引

     一:普通索引 1创建一个新的数据库 > use toto; switched to db toto > show dbs; admin (empty) local 0.078GB & ...

  4. Light oj 1138 - Trailing Zeroes (III) 【二分查找 &amp;&amp; N!中末尾连续0的个数】

    1138 - Trailing Zeroes (III) problem=1138"> problem=1138&language=english&type=pdf&q ...

  5. 安装robotframework-ride

    先安装好python并配置好环境变量 1.Windows+r后输入CMD 安装robotframework框架 2.输入pip install robotframework 安装RIDE前需要安装的依 ...

  6. 运行Django项目指定IP和端口

    默认IP和端口 python manage.py runserver 指定端口: python manage.py runserver 192.168.12.12:8080 此时会报错,我们需要修改配 ...

  7. POJ 3083 BFS+DFS 40行

    题意:给你一个迷宫. 先输出当左转优先的时候走的路程长度,再输出当右转优先时走的路程长度,最后输出从起点到终点的最短路程长度. 嗯嗯 奴哥活跃气氛的题.随便写了写.. 此题 知道了思路以后就是水题了. ...

  8. A - HQ9+

    Problem description HQ9+ is a joke programming language which has only four one-character instructio ...

  9. MySQL命令学习之技巧(博主推荐)

    关于,这篇博客呢,是

  10. Oracle 动态sql小例子

    错误写法: create or replace procedure testproce20130228issqlstr varchar2(8000);date1 varchar2(10);begins ...