看了别人的题解
首先这题是一个dp

dp[i][j] i是当前有多少个a j是当前有多少个ab子序列

dp[i][j] = dp[i+1][j]*Pa + dp[i][i+j]*Pb;
i,j 时加一个a之后会变成i+1, j
i,j 时加一个b之后会变成i, i+j

除此之外的话对于i+j >= k的情况
其实是一个几何分布来概括,此时
dp[i][j] = i+j + 1/p - 1

#include<iostream>
#include<map>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<stack>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 1e3+5;
const int MOD = 1e9+7;
#define MS(x,y) memset(x,y,sizeof(x))
#define MP(x, y) make_pair(x, y)
const int INF = 0x3f3f3f3f; ll dp[N][N]; ll inv(ll a) {
ll ans = 1; int tim = MOD-2;
while(tim) {
if(tim & 1) ans = ans*a % MOD;
a = a*a % MOD;
tim >>= 1;
}
return ans;
} int main() {
int k; ll a, b;
while(~scanf("%d %lld %lld", &k, &a, &b)) {
memset(dp, 0, sizeof(dp));
ll all = a+b; a = a*inv(all) %MOD;
b = b*inv(all) %MOD;
ll tt = a*inv(b) % MOD; for(int i = k; i >= 0; --i) {
for(int j = k; j >= 0; --j) {
if(i + j >= k) {
dp[i][j] = (i + j + tt) % MOD;
} else {
dp[i][j] = (dp[i + 1][j]*a + dp[i][i + j]*b) % MOD;
}
}
} printf("%lld\n", dp[1][0]);
}
return 0;
}

Good Bye 2017 D. New Year and Arbitrary Arrangement的更多相关文章

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

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

  2. Good Bye 2017 A B C

    Good Bye 2017 A New Year and Counting Cards 题目链接: http://codeforces.com/contest/908/problem/A 思路: 如果 ...

  3. Good Bye 2017 部分题解

    D. New Year and Arbitrary Arrangement 分析 \(dp[i][j]\) 表示已有 \(i\) 个 \(a\) 和 \(j\) 个 \(ab\) 的情况下继续构造能得 ...

  4. Good Bye 2017

    太菜了啊,一不小心就goodbye rating了 A. New Year and Counting Cards time limit per test 1 second memory limit p ...

  5. [Codeforces]Good Bye 2017

    A - New Year and Counting Cards #pragma comment(linker, "/STACK:102400000,102400000") #inc ...

  6. Codeforces 908 D.New Year and Arbitrary Arrangement (概率&期望DP)

    题目链接:New Year and Arbitrary Arrangement 题意: 有一个ab字符串,初始为空. 用Pa/(Pa+Pb)的概率在末尾添加字母a,有 Pb/(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. Hello 2018, Bye 2017

    2017年过去了,过去一年经历了太多,改变了好多好多,可以说人生进入了另一个阶段,有可能是成熟吧. 回顾2017 去年换了新工作,离开了将近工作了8年的公司,不带走一丝云彩,为其任劳任怨,最后没有任何 ...

随机推荐

  1. JS代码中加上alert才能正常显示效果

    模拟一个生成验证码的效果,发现JS代码中加上alert可以正常刷新,没有alert时图片就会丢失,找到解决方法,但是还不是很明白,先记录下来. 生成验证码的servlet代码如下: package s ...

  2. BZOJ 3907: 网格 [Catalan数 高精度]

    3907: 网格 Time Limit: 1 Sec  Memory Limit: 256 MBSubmit: 402  Solved: 180[Submit][Status][Discuss] De ...

  3. BZOJ 2083: [Poi2010]Intelligence test [vector+二分]

    2083: [Poi2010]Intelligence test Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 469  Solved: 227[Su ...

  4. 【转】如何解决plsql查询oracle数据库语句where条件带有中文无法匹配结果

    一.问题描述 之前使用PLSQL查询oracle数据库可以正常查询统计结果,由于换了个电脑,重新安装之后,同样的sql查询语句同一个数据库,无法正常查询结果,如下图所示 二.解决办法 1. 查询数据当 ...

  5. xBIM WeXplorer xViewer 基本应用

    目录 基础 xBIM WeXplorer 简要介绍 xBIM WeXplorer xViewer 基本应用 xBIM WeXplorer xViewer 浏览器检查 xBIM WeXplorer xV ...

  6. win8 -telnet安装

    控制面板->程序-> 启动或关闭windows功能->选择telnet服务器和telnet客户端->确定 为了安全起见,我们可以设置为手动器用telnet,右键计算机-> ...

  7. 一个很好的MySQL在线学习平台

    一个很好的MySQL在线学习平台 https://www.techonthenet.com/sql/

  8. iOS通知传值的使用

    通知 是在跳转控制器之间常用的传值代理方式,除了代理模式,通知更方便.便捷,一个简单的Demo实现通知的跳转传值. 输入所要发送的信息 ,同时将label的值通过button方法调用传递, - (IB ...

  9. MySQL数据库基础(四)(子查询与链接)

    1.子查询简介 其中,所谓的"外层查询"并不是指"查找",指的是所有SQL语句的统称:结构化查询语言(Structured Query Language),简称 ...

  10. 正本清源区块链——Caoz

    正本清源区块链 说明:以下内容整理自Caoz的<正本清源区块链>,如有不妥,请联系我修改或删除. 简介 不讨论炒币!不讨论炒币!不讨论炒币! 本课程内容分为两部分: 第一部分,烧脑篇,介绍 ...