题面在这里

题意

给定三个数\(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. 练手项目:利用pygame库编写射击游戏

    本项目使用pygame模块编写了射击游戏,目的在于训练自己的Python基本功.了解中小型程序框架以及学习代码重构等.游戏具有一定的可玩性,感兴趣的可以试一下. 项目说明:出自<Python编程 ...

  2. mysql 在一个实例运行情况下再搭建一个实例

    配置mysql服务 详细步骤,请参考(http://study.lishiming.net/chapter17.html#mysql), 阿铭只把简单步骤写一下. 根据阿铭提供的地址,假如你已经搭建好 ...

  3.     My GitHub

    0.引言 利用python开发,借助Dlib库捕获摄像头中的人脸,进行实时特征点标定: 图1 工程效果示例(gif) 图2 工程效果示例(静态图片) (实现比较简单,代码量也比较少,适合入门或者兴趣学 ...

  4. web端表格测试用例

    表格测试: 表格内容列表排序功能是否正常每一栏的宽度是否足够宽,表格里的文字是否都有折行?是否有因为某一格的内容太多,而将整行的内容拉长?表格是否能左(右)添加(删除)列,表格是否能上(下)添加(删除 ...

  5. Visual Studio 2017 Enterprise 发布 15.4 版本,离线安装包百度网盘下载。

    Visual Studio 2017 于2017年10月13日发布 15.4 版本.该版本包含多项生产力改进,支持 .NET Standard 2.0 ,并且可以开启 Xamarin Live Pla ...

  6. Nginx和Apache有什么区别?

    Nginx抗并发,nginx 处理请求是异步非阻塞的,而apache 则是阻塞型的,在高并发下nginx 能保持低资源低消耗高性能. Apache  rewrite ,比nginx 的rewrite ...

  7. React Native填坑之旅 -- FlatList

    在React Native里有很多种方法来创建可滚动的list.比如,ScrollView和ListView.他们都各有优缺点.但是在React Native 0.43里增加了两种行的list vie ...

  8. Spring 代理对象,cglib,jdk的问题思考,AOP 配置注解拦截 的一些问题.为什么不要注解在接口,以及抽象方法.

    可以被继承 首先注解在类上是可以被继承的 在注解上用@Inherited /** * Created by laizhenwei on 17:49 2017-10-14 */ @Target({Ele ...

  9. css线性渐变兼容

    css线性渐变兼容 background: linear-gradient(top, rgba(54, 77, 127, 0.8), rgba(54, 77, 127, 0.8)); backgrou ...

  10. java使用poi将html导出word,默认打开页面视图

    <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:o ...