设状态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. 安装 KB2844286 导致SharePoint 2010 XSLT web part 显示出现错误

    上周末给Windows 打完补丁后,周一在通过From SharePoint的方式插入图片时,出现了如下错误: Unable to display this Web Part. To troubles ...

  2. HDU3183 RMQ/贪心

    A Magic Lamp Problem Description Kiki likes traveling. One day she finds a magic lamp, unfortunately ...

  3. luogu2746 校园网

    题目大意: 一些学校连入一个电脑网络.那些学校已订立了协议:每个学校都会给其它的一些学校分发软件(称作“接受学校”).注意即使 B 在 A 学校的分发列表中, A 也不一定在 B 学校的列表中. 你要 ...

  4. LINQ Query Expressions

    https://msdn.microsoft.com/en-us/library/bb397676(v=vs.100).aspx Language-Integrated Query (LINQ) is ...

  5. 【POJ 1456】 Supermarket

    [题目链接] http://poj.org/problem?id=1456 [算法] 贪心 + 堆 [代码] #include <algorithm> #include <bitse ...

  6. 【BZOJ 1590】 Secret Message

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1590 [算法] 字典树 [代码] #include<bits/stdc++.h ...

  7. c++ 数据预处理(数据去噪,归一化)

    正态分布3σ原则,把3倍方差之外的点设想为噪声数据来排除. 归一化,将数据经过处理之后限定到一定的范围内,一般都会将数据限定到[0,1]. #include <iostream>#incl ...

  8. iOS网络开发工具集----字符串操作和时间操作

    一.字符串的操作方法 #pragma mark - 创建字符串 - (void)CreatString { // <1> 创建字符串 NSString *strS = @"Thi ...

  9. leetcode排列组合相关

    目录 78/90子集 39/40组合总和 77组合 46/47全排序,同颜色球不相邻的排序方法 78/90子集 输入: [1,2,2] 78输出: [[], [1], [2], [1 2], [2], ...

  10. c++调用DOS命令,不显示黑屏

    WinExec("Cmd.exe /C md c://12", SW_HIDE); 注释:/c是什么意思,不用/C会报错 CMD [/A | /U] [/Q] [/D] [/E:O ...