[CodeForces]908D New Year and Arbitrary Arrangement
设状态f[i][j]表示有i个a,j个ab的期望
发现如果i+j>=k的话就再来一个b就行了。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int mod=1e9++;
int k,pa,pb,inva,invb,f[][];
int ksm(int d,int z) {
int res=;
while(z) {
if(z&) res=(1ll*res*d)%mod;
d=(1ll*d*d)%mod;
z>>=;
}
return res;
}
int main() {
scanf("%d%d%d",&k,&pa,&pb);
int tp=ksm(pa+pb,mod-);
pa=1ll*pa*tp%mod,pb=1ll*pb*tp%mod;
invb=ksm(pb,mod-);
for(int i=k;i;i--) {
for(int j=k;~j;j--) {
if(i+j>=k) {f[i][j]=(1ll*i+1ll*j+1ll*pa*invb)%mod;continue;}
f[i][j]=(1ll*f[i+][j]*pa+1ll*f[i][j+i]*pb)%mod;
}
}
cout<<f[][];
return ;
}
New Year and Arbitrary Arrangement
[CodeForces]908D New Year and Arbitrary Arrangement的更多相关文章
- Codeforces 908D New Year and Arbitrary Arrangement(概率DP,边界条件处理)
题目链接 Goodbye 2017 Problem D 题意 一个字符串开始,每次有$\frac{pa}{pa+pb}$的概率在后面加一个a,$\frac{pb}{pa+pb}$的概率在后面加一个 ...
- CF 908D New Year and Arbitrary Arrangement——期望dp
题目:http://codeforces.com/contest/908/problem/D 注意是子序列.加一个a对ab个数无影响:加一个b使ab个数多出它前面的a那么多个.所以状态里记录有多少个a ...
- 908D New Year and Arbitrary Arrangement
传送门 分析 代码 #include<iostream> #include<cstdio> #include<cstring> #include<string ...
- Solution -「CF 908D」New Year&Arbitrary Arrangement
\(\mathcal{Description}\) Link. 给定 \(n,p_a,p_b\),初始有一个空串,每次操作有 \(\frac{p_a}{p_a+p_b}\) 的概率在其后添加字 ...
- Codeforces 908 D.New Year and Arbitrary Arrangement (概率&期望DP)
题目链接:New Year and Arbitrary Arrangement 题意: 有一个ab字符串,初始为空. 用Pa/(Pa+Pb)的概率在末尾添加字母a,有 Pb/(Pa+Pb)的概率在末尾 ...
- 【CodeForces】908 D. New Year and Arbitrary Arrangement
[题目]Good Bye 2017 D. New Year and Arbitrary Arrangement [题意]给定正整数k,pa,pb,初始有空字符串,每次有pa/(pa+pb)的可能在字符 ...
- 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 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 ...
- 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 ...
随机推荐
- Apache Traffic Server 5.3.1公布
本文来源于我在InfoQ中文站翻译的文章,原文地址是:www.infoq.com/cn/news/2015/07/traffic-server-5.3.1-release 近日,Apache软件基金会 ...
- Eclipse集成Resinserver
因为Resin在Eclipse下的表现丝毫不亚于Tomcat,小编决定带领众小弟一起学习使用Resin.虽然小编身边也没有什么大牛在使用Resin,但看到Resin的广告已经吹到天边了.所以还 ...
- 游戏人生(一),我的lua之旅:那些坑爹的CCBReaderLoad
首先,我们说说这个CCBReaderLoad. 这个脚本是cocos2dx自带的一个lua+cocosbuilder 的工具,详细功能呐,往下看. 先来看下我遇到的一个问题: ----美工给了我一个. ...
- grails一对多双向关联
前面分享了一些学习grails的心得,可是grails的知识还远不止这些,这次整理了一点有关grails一对多双向关联关系的知识.我认为这样的关联用的地方太多了,这次准备的样例是城市和区域的相关样例. ...
- Python内置的字符串处理函数
生成字符串变量 str='python String function' 字符串长度获取:len(str) 例:print '%s length=%d' % (str,len(str)) 连接字符 ...
- light oj1074
Description The people of Mohammadpur have decided to paint each of their houses red, green, or blue ...
- linux驱动由浅入深系列:tinyalsa(tinymix/tinycap/tinyplay/tinypcminfo)音频子系统之一【转】
本文转载自:http://blog.csdn.net/radianceblau/article/details/64125411 目前linux中主流的音频体系结构是ALSA(Advanced Lin ...
- CSS实现列表li边框重合问题
CSS实现列表li边框重合问题 2017年04月13日 21:04:18 阅读数:5066 在我们写东西的时候经常要用到ul,但是也经常会出现li边框重合的问题,如下图: 可以看到每个格子的右边框和 ...
- MySql c#通用类
using System; using System.Collections.Generic; using System.Linq; using System.Text;//导命名空间 using S ...
- android黑科技系列——Xposed框架实现拦截系统方法详解
一.前言 关于Xposed框架相信大家应该不陌生了,他是Android中Hook技术的一个著名的框架,还有一个框架是CydiaSubstrate,但是这个框架是收费的,而且个人觉得不怎么好用,而Xpo ...