题目链接: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 @。@#,这题题意其实我也没看太懂,后来看了别人的博客才勉强写出来。。。

 #include<bits/stdc++.h>
using namespace std;
const int MAX_N = 5e3+;
const int MOD = 1e9+;
long long k,pa,pb;
int DP[MAX_N][MAX_N];
long long quick_mod(long long x,int p)
{
long long ans = ;
long long base = x;
while(p)
{
if(p&) ans = ans*base %MOD;
p>>=;
base = (base*base)%MOD;
}
return ans;
}
long long inv(long long x)
{
return quick_mod(x,MOD-);
}
long long make_DP(long long i,long long j)
{
if(i+j>=k)
return (i+j+pa*inv(pb)%MOD)%MOD;
if(DP[i][j] != -)
return DP[i][j];
return DP[i][j] = ((pa*make_DP(i+,j)%MOD) + (pb*make_DP(i,i+j)%MOD))*inv(pa+pb) %MOD;
}
int main()
{
while(cin>>k>>pa>>pb)
{
memset(DP,-,sizeof(DP));
//cout<<"......"<<DP[2][0]<<endl;
cout<<make_DP(,)<<endl;
}
return ;
}

  

Codeforces 908 D.New Year and Arbitrary Arrangement (概率&期望DP)的更多相关文章

  1. 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 ...

  2. Codeforces - 1264C - Beautiful Mirrors with queries - 概率期望dp

    一道挺难的概率期望dp,花了很长时间才学会div2的E怎么做,但这道题是另一种设法. https://codeforces.com/contest/1264/problem/C 要设为 \(dp_i\ ...

  3. 【CodeForces】908 D. New Year and Arbitrary Arrangement

    [题目]Good Bye 2017 D. New Year and Arbitrary Arrangement [题意]给定正整数k,pa,pb,初始有空字符串,每次有pa/(pa+pb)的可能在字符 ...

  4. 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 ...

  5. Codeforces 446D - DZY Loves Games(高斯消元+期望 DP+矩阵快速幂)

    Codeforces 题目传送门 & 洛谷题目传送门 神仙题,%%% 首先考虑所有格子都是陷阱格的情况,那显然就是一个矩阵快速幂,具体来说,设 \(f_{i,j}\) 表示走了 \(i\) 步 ...

  6. [CodeForces]908D New Year and Arbitrary Arrangement

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

  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 Round #164 (Div. 2) E. Playlist 贪心+概率dp

    题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...

  9. [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)

    [Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ...

随机推荐

  1. [原创]获取JS数组最大值、最小值

    核心关键 JS有Array数组对象,使用prototype内置属性扩展,增加Array数组max().min()方法 具体代码 //最小值 Array.prototype.min = function ...

  2. 奇怪的.strip(alir) #()里面有东西 待问老师........

    #关于strips = "alirrijgbskbbbbbar"s1 = s.strip("alir") # strip 去空格,strip(sth),括号里有 ...

  3. Ubuntu eclipse安装

    apt-get install eclipse eclipse-cdt eclipse-jdt  # don't include eclipse if you have it already afte ...

  4. Oracle学习(十一):PL/SQL

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/v123411739/article/details/30231659 1.知识点:能够对照以下的录屏 ...

  5. 通过golang 查询impala

    cloudera官方没有提供impala基于golang的驱动,github有github.com/bippio/go-impala package main import ( "conte ...

  6. Jsp实现在线作业提交系统

    Jsp实现在线作业提交系统 作为 Computer Science 的学生,凌晨四点之前睡都应该感到羞耻. 项目托管地址:https://github.com/four-in-the-morning/ ...

  7. virtualbox+vagrant学习-2(command cli)-21-vagrant up命令

    Up 格式: vagrant up [options] [name|id] 这个命令根据你的Vagrantfile文件创建和配置客户机. 这是“vagrant”中最重要的一个命令,因为它是创建任何va ...

  8. VMware 虚拟机安装

    虚拟机下载 VMware官网地址:https://www.vmware.com/ 进行官网后,点击左边的下载图标,然后 作系统选择合适的产品,在这里以Windows系统为例,点击转至下载,如下图所示. ...

  9. highchart本地化导出图片

    因为项目执行在内容,并且本身自带的功能是想highcharts  server写文件然后再下载的,所以 highchart本地化导出图片 就非常须要. 第一步改动export.js 里的URl 在在e ...

  10. MyBatis的缓存分析

    一:MyBatis缓存简介 MyBatis支持声明式数据缓存(declarative data caching).当一条SQL语句被标记为“可缓存”后,首次执行它时从数据库获取的所有数据会被存储在一段 ...