题目链接:New Year and Arbitrary Arrangement 题意: 有一个ab字符串,初始为空. 用Pa/(Pa+Pb)的概率在末尾添加字母a,有 Pb/(Pa+Pb)的概率在末尾添加字母b,当出现≥k个ab子串时立即停止添加字母,求最后期望的ab子串个数.(子串ab不要求连续) 例子:当k=1,aab含2个ab,bbabbab时不可能出现的,因为到了bbab就会停止添加字母. 题解: 期望DP DP果然是智商的分界线 orz @.@#,这题题意其实我也没看太懂,后来看了别人…
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…
一道挺难的概率期望dp,花了很长时间才学会div2的E怎么做,但这道题是另一种设法. https://codeforces.com/contest/1264/problem/C 要设为 \(dp_i\) 表示第 \(i\) 个格子期望经过多少次,所以 \(dp_{n+1}=1\). https://www.cnblogs.com/suncongbo/p/11996219.html…
[题目]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]表示前缀…
题目: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[…
Codeforces 题目传送门 & 洛谷题目传送门 神仙题,%%% 首先考虑所有格子都是陷阱格的情况,那显然就是一个矩阵快速幂,具体来说,设 \(f_{i,j}\) 表示走了 \(i\) 步到达 \(j\) 点的概率,那显然有 \(dp_{i+1,k}\leftarrow dp_{i,j}\times\dfrac{1}{\delta^+(j)}\)(\(j,k\) 之间有边相连),矩阵快速幂优化一下即可,最终答案即为 \(f_{k-1,n}\),时间复杂度 \(n^3\log k\). 接下来…
设状态f[i][j]表示有i个a,j个ab的期望 发现如果i+j>=k的话就再来一个b就行了. #include <iostream> #include <cstdio> #include <cstring> using namespace std; +; ][]; int ksm(int d,int z) { ; while(z) { ) res=(1ll*res*d)%mod; d=(1ll*d*d)%mod; z>>=; } return res…
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…
题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory limit per test 256 megabytes 问题描述 Manao's friends often send him new songs. He never listens to them right away. Instead, he compiles them into a play…
[Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每通过一关后可以选择继续下一关或者时间清0并从第一关开始,先要求通过所有关卡的时间和不能超过R才算彻底通关,问直到彻底通关位置的游戏时间的期望值为多少 分析 二分从头开始通关的用时期望mid 设\(dp[i][j]\)表示通前i关,当前时间为j的期望,倒推期望. 若超时重新开始,则\(dp[i][j]…