设状态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. cocos2d-html5开发之本地数据存储

    做游戏时常常须要的一个功能呢就是数据的保存了,比方游戏最高分.得到的金币数.物品的数量等等.cocos2d-html5使用了html5.所以html5的数据保存方法是对引擎可用的: html5本地数据 ...

  2. HDU5195 线段树+拓扑

    DZY Loves Topological Sorting Problem Description A topological sort or topological ordering of a di ...

  3. Newtonsoft.Json 序列化日期问题解决

    上代码 其中的使用方法和UserInfo实体对象就不贴代码了. /// <summary> /// 把对象转成json字符串 /// </summary> /// <pa ...

  4. Aviator

    Aviator 简介¶ Aviator是一个高性能.轻量级的java语言实现的表达式求值引擎,主要用于各种表达式的动态求值.现在已经有很多开源可用的java表达式求值引擎,为什么还需要Avaitor呢 ...

  5. idea使用svn

    一.在idea中配置svn 二.导出maven项目 连接svn 点击checkout 点击ok就可以 到Commit Changes 这里有几个选项需要了解的: Auto-update after c ...

  6. C#格式化年月日截取

     //if (bm.Name == "DateYear") //年                 //{                 //    bm.Select();   ...

  7. B - String Task

    Problem description Petya started to attend programming lessons. On the first lesson his task was to ...

  8. Spark Streaming基础概念

    为了更好地理解Spark Streaming 子框架的处理机制,必须得要自己弄清楚这些最基本概念. 1.离散流(Discretized Stream,DStream):这是Spark Streamin ...

  9. 2018.10.9 上线发现elasticsearch写入速度超级慢,原来罪魁祸首是阿里云服务的OSS的锅

    问题描述: 按照项目计划,今天上线部署日志系统(收集线上的所有日志,便于问题排查). 运维按照以前的部署过程,部署elasticsearch,部署结束之后,通过x-pack的monitor发现elas ...

  10. ThinkPHP5中的助手函数

    load_trait:快速导入Traits,PHP5.5以上无需调用 /** * 快速导入Traits PHP5.5以上无需调用 * @param string    $class trait库 *  ...