New Year and Arbitrary Arrangement time limit per test2 seconds You are given three integers k, pa and pb. You will construct a sequence with the following algorithm: Initially, start with the empty sequence. Each second, you do the following. With p…
[题目]Good Bye 2017 D. New Year and Arbitrary Arrangement [题意]给定正整数k,pa,pb,初始有空字符串,每次有pa/(pa+pb)的可能在字符串末尾+a,有pb/(pa+pb)的可能在字符串末尾+b,求加到组成至少k对子序列“ab"时的期望子序列“ab”数.k<=1000,pa,pb<=10^6. [算法]期望DP [题解]主要问题在于字符串无限延伸,那么需要考虑记录前缀的关键量来为DP设置终止状态. 设f[i][j]表示前缀…
Discription You are given three integers k, pa and pb. You will construct a sequence with the following algorithm: Initially, start with the empty sequence. Each second, you do the following. With probability pa / (pa + pb), add 'a' to the end of the…
题目:http://codeforces.com/contest/908/problem/D 首先,设 f[i][j] 表示有 i 个 a,j 个 ab 组合的期望,A = pa / (pa + pb) , B = pb / (pa + pb) 那么 f[i][j] = A * f[i+1][j] + B * f[i][i+j] 当 i+j >= k 时,再出现一个 b 就会结束,所以此时: f[i][j] = f[i][i+j] * B + f[i+1][i+j+1] * A * B + f[…