题面在这里

题意

给定三个数\(k,pa,pb\),每次有\(\frac{pa}{pa+pb}\)的概率往后面添加一个'\(a\)',每次有\(\frac{pb}{pa+pb}\)的概率往后面添加一个'\(b\)'当出现了\(k\)个形如'\(ab\)'的子序列(不用连续)时停止。求最后的形如'\(ab\)'的子序列个数的期望。答案对\(1e9+7\)取模。

\(k\leq 1000\)

sol

一看到\(k\leq 1000\)马上想到\(f[i][j]\)表示已经有\(i\)个\(a\),目前'\(ab\)'的子序列的个数为\(j\)的期望

转移:$$f[i][j]=f[i][j]+\frac{pa}{pa+pb}*f[i+1][j]+\frac{pb}{pa+pb}f[i][i+j]$$

但是需要考虑\(bbb...bbab\)(前面无限个'b')和\(abbaaa...\)(后面无限个'a')的情况

首先前面的'\(b\)'不管有多少都不需要考虑

然后考虑的就是后面无限个'a'的情况

我们注意到,如果状态\(f[i][j]\)中的\(i+j\geq k\),那么只需要再加上一个'\(b\)'统计就会结束

那么\(f[i][j]\)的求解实际上就是在解一个无穷级数:

\[f[i][j]=\frac{pb}{pa+pb}(i+j)+\frac{pa}{pa+pb}\times\frac{pb}{pa+pb}(i+j+1)+(\frac{pa}{pa+pb})^{2}\times\frac{pb}{pa+pb}(i+j+2)+...
\]

可以化简成

\[f[i][j]=i+j+\frac{pa}{pb}
\]

那么对于\(i+j\geq k\)的情况直接算出答案,其余的情况递推求解就好

代码

#include<bits/stdc++.h>
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<complex>
#include<vector>
#include<cstdio>
#include<string>
#include<bitset>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define mp make_pair
#define pb push_back
#define RG register
#define il inline
using namespace std;
typedef unsigned long long ull;
typedef vector<int>VI;
typedef long long ll;
typedef double dd;
const dd eps=1e-10;
const int mod=1e9+7;
const int N=1010;
const int M=90000;
il ll read(){
RG ll data=0,w=1;RG char ch=getchar();
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')w=-1,ch=getchar();
while(ch<='9'&&ch>='0')data=data*10+ch-48,ch=getchar();
return data*w;
} il void file(){
//freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);
} il ll poww(ll a,ll b){RG ll ret=1;for(a%=mod;b;b>>=1,a=a*a%mod)
if(b&1)ret=ret*a%mod;return ret;} int k,pa,pb,rev,revb,f[N][N];
il int search(int x,int y){
if(f[x][y])return f[x][y];
if(x+y>=k)return f[x][y]=(x+y+1ll*pa*revb%mod)%mod;
return f[x][y]=(1ll*pa*rev%mod*search(x+1,y)%mod+1ll*pb*rev%mod*search(x,x+y)%mod)%mod;
} int main()
{
k=read();pa=read();pb=read();
rev=poww(pa+pb,mod-2);revb=poww(pb,mod-2);
printf("%d\n",search(1,0));
return 0;
}

[CF908D]New Year and Arbitrary Arrangement的更多相关文章

  1. CF908D New Year and Arbitrary Arrangement(期望Dp+数学)

    题目大意:给你一个空字符串,你有\(\frac{pa}{pa+pb}\)的概率往字符串最后面加个\(a\),\(\frac{pb}{pa+pb}\)的概率往字符串最后面加个\(b\),当子序列\(ab ...

  2. CF908D New Year and Arbitrary Arrangement 期望、DP

    题目传送门 题意:给出正整数$pa,pb,k$,最开始你有一个空串,每一次你有$\frac{pa}{pa + pb}$的概率向串最后放一个$a$,有$\frac{pb}{pa + pb}$的概率向串最 ...

  3. $CF908D\ New\ Year\ and\ Arbitrary\ Arrangement$ 期望$dp$

    正解:期望$dp$ 解题报告: 传送门$QwQ$ 阿关于题目里那个形如$ab$的子序列我说下,,,我我我之前$get$了好久$QAQ$.这里子序列的个数的定义是这样儿的,举个$eg$,$aabb$,就 ...

  4. CF908D New Year and Arbitrary Arrangement 题解

    \(0.\) 前言 有一天 \(Au\) 爷讲期望都见到了此题,通过写题解来加深理解. \(1.\) 题意 将初始为空的序列的末尾给定概率添加 \(a\) 或 \(b\),当至少有 \(k\) 对 \ ...

  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]908D New Year and Arbitrary Arrangement

    设状态f[i][j]表示有i个a,j个ab的期望 发现如果i+j>=k的话就再来一个b就行了. #include <iostream> #include <cstdio> ...

  8. Codeforces New Year and Arbitrary Arrangement

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

  9. CF908D Arbitrary Arrangement

    题目大意: 给定三个数\(k\) , \(p_a\) , \(p_b\) 每次有\(\frac{p_a}{p_a+p_b}\)的概率往后面添加一个'a' 每次有\(\frac{p_b}{p_a+p_b ...

随机推荐

  1. 高仿QQ Xplan的H5页面

    概述 这个h5的主要玩法很简单:地球自转的时候会播放背景音乐(比如海浪声),为了找到这个声音是从哪个地球上哪个地方传来的,需要长按下方的按钮,这时地球会自动转动到目标地点,然后镜头拉近,穿过云层,最后 ...

  2. angularjs 服务详解

    一.服务 服务提供了一种能在应用的整改生命周期内保持数据的方法,它能够在控制器之间进行通信,并保持数据的一致性. 1.服务是一个单例对象,在每个应用中只会被实例化一次(被$injector): 2.服 ...

  3. ABP框架源码学习之授权逻辑

    asp.net core的默认的几种授权方法参考"雨夜朦胧"的系列博客,这里要强调的是asp.net core mvc中的授权和asp.net mvc中的授权不一样,建议先看前面& ...

  4. docker容器安装及使用技巧

    关于docker前言 A)首先是关于虚拟化 虚拟化我们可以简单的理解为一种资源管理方式.有如下几种虚拟化的方式: 1.完全虚拟化:对底层硬件实现完全的虚拟.例如:Vmware Workstation ...

  5. spring 代码中获取ApplicationContext(@AutoWired,ApplicationListener)

    2017年度全网原创IT博主评选活动投票:http://www.itbang.me/goVote/234    学习spring框架时间不长,一点一滴都得亲力亲为.今天忽然觉得老是通过@Autowir ...

  6. Failure to transfer org.apache.maven:maven-archiver:pom:2.5 from http://repo.maven.apache.org/ maven2 was cached in the local repository, resolution will not be reattempted until the update interv

    Failure to transfer org.apache.maven:maven-archiver:pom:2.5 from http://repo.maven.apache.org/  mave ...

  7. ubuntu重启、关机命令

    重启命令 :     1.reboot     2.shutdown -r now 立刻重启    3.shutdown -r 10 过10分钟自动重启    4.shutdown -r 20:35 ...

  8. IOS 使用cocoapods后无法导入头文件问题

    IOS 使用cocoapods后无法导入头文件问题 这时候如果你发现import的时候没有提示AFN e t wo r k i n g.h的文件,可以在target-Build Settings下修改 ...

  9. LOJ6000 - 「网络流 24 题」搭配飞行员

    原题链接 题意简述 求二分图的最大匹配. 题解 这里写的是匈牙利算法. 表示节点的当前匹配. 为真表示在这一轮匹配中,无法给节点一个新的匹配.所以如果为真就不用再dfs它了,直接continue就好. ...

  10. 【转载】一行代码加载网络图片到ImageView——Android Picasso

    原文链接:一句代码加载网络图片到ImageView——Android Picasso  注意:此处使用下面代码需要先配置一下gradle,下载所需包. 具体操作如下图: compile 'com.sq ...