Codeforces 908 D.New Year and Arbitrary Arrangement (概率&期望DP)
题目链接: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)的更多相关文章
- 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 ...
- Codeforces - 1264C - Beautiful Mirrors with queries - 概率期望dp
一道挺难的概率期望dp,花了很长时间才学会div2的E怎么做,但这道题是另一种设法. https://codeforces.com/contest/1264/problem/C 要设为 \(dp_i\ ...
- 【CodeForces】908 D. New Year and Arbitrary Arrangement
[题目]Good Bye 2017 D. New Year and Arbitrary Arrangement [题意]给定正整数k,pa,pb,初始有空字符串,每次有pa/(pa+pb)的可能在字符 ...
- 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 ...
- Codeforces 446D - DZY Loves Games(高斯消元+期望 DP+矩阵快速幂)
Codeforces 题目传送门 & 洛谷题目传送门 神仙题,%%% 首先考虑所有格子都是陷阱格的情况,那显然就是一个矩阵快速幂,具体来说,设 \(f_{i,j}\) 表示走了 \(i\) 步 ...
- [CodeForces]908D New Year and Arbitrary Arrangement
设状态f[i][j]表示有i个a,j个ab的期望 发现如果i+j>=k的话就再来一个b就行了. #include <iostream> #include <cstdio> ...
- Codeforces New Year and Arbitrary Arrangement
New Year and Arbitrary Arrangement time limit per test2 seconds You are given three integers k, pa a ...
- Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp
题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...
- [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)
[Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ...
随机推荐
- Python学习---IO的异步[asyncio +aiohttp模块]
aiohttp aiohttp是在asyncio模块基础上封装的一个支持HTTP请求的模块,内容比8.4.2[基于asyncio实现利用TCP模拟HTTP请求]更全面 安装aiohttp: pip3 ...
- C++暑期学习笔记
# C++初步学习笔记 一.命名空间(namespace)相关 1 个人理解: 为了避免整合资源中存在的重名矛盾而采取的区别资源的措施: 2 命名空间的定义: 比如要定义一个命名空间A: namesp ...
- 第一次项目冲刺(Alpha版本)2017/11/14
一.站立式会议 在宿舍进行了第一次会议 会议内容: 1.做了简单的分工 2.提出个人对任务是否有困难 3.规定完成时间在第三天之前 4.商量初步的代码规范 二.分工 三.任务分解图 四.燃尽图 五.数 ...
- [DAViCHi/SeeYa/T-ARA][원더우먼][Wonder Woman]
歌词来源:http://music.163.com/#/song?id=5371229 作曲 : 赵英秀 [作曲 : 赵英秀] [作曲 : 赵英秀] 作词 : K-Smith [作词 : KSmith ...
- postGresql关键字字段重名
在postGresql中如果关键字和自定义的字段重名 即使使用[ ](中括号)或者 ' '(单引号)都没有用,经本人实验. 如果使用" "(双引号),则可以.
- URL地址理解
/ 表示相对目录的根目录./ 表示相对目录的本层目录../ 表示相对目录的上层目录
- golang第三方库goconfig的使用
参考地址:http://studygolang.com/articles/818 详细的解析可以看上面链接,这里只做一点简单介绍 先安装好包,然后导入 import ( "githu ...
- RLE Iterator LT900
Write an iterator that iterates through a run-length encoded sequence. The iterator is initialized b ...
- Linux centos修改防火墙为iptables
防火墙配置 CentOS 7默认使用的是firewall作为防火墙,这里改为iptables防火墙. firewall操作: # service firewalld status; #查看防火墙状态 ...
- jQuery内容横向拖拽滚动
如果有业务需求:使用横向滚动,而又不想用滚动条,可以使用横向拖拽滚动,主要是利用元素的scrollLeft特性: 废话不多说直接上代码: css: .box{ width:100%; height:3 ...