看了别人的题解
首先这题是一个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. MySQL修改密码的三种方法

      MySQL修改密码的三种方法 1.方法1: 2.方法2: 3.方法3:        

  2. Cookie、session和localStorage、以及sessionStorage之间的区别

    一.Cookie.session和localStorage的区别 cookie的内容主要包括:名字.值.过期时间.路径和域.路径与域一起构成cookie的作用范围.若不设置时间,则表示这个cookie ...

  3. coredump故障分析

    如果一个程序运行3天后才会出错,这个时候 难道需要我们一直用GDB调试程序3天吗? 这个时候我们就需要使用到core  dump: 1.Core Dump又叫核心转存.当程序在运行过程中发生异常, 这 ...

  4. uboot之位置无关代码解析

    在之前的话 新年过去了,那么久没有好好学习,感觉好颓废,现在就uboot的一些基础问题做一些笔记,顺便分享给大家,不过由于见识有限,如果有不足之处请多多指教. 位置无关?什么意思?我们先了解一些基础知 ...

  5. Docker命令行安装Shipyard

    1.下载自动部署Shell脚本 curl -sSL https://shipyard-project.com/deploy | bash -s 自动部署脚本中, 包括以下参数: ACTION: 表示可 ...

  6. JDK1.7源码分析01-Collection

    同步发布:http://www.yuanrengu.com/index.php/20180221.html Java的集合类主要由两个接口派生而出:Collection和Map.Collection是 ...

  7. Linux命令之tar-rsync

    一.tar命令 可以对文件和目录进行打包压缩(相较于zip.gzip.bzip2不能对目录进行压缩,tar是一大优势) 用途:制作归档文件.释放归档文件 基本格式: 压缩---> tar  [选 ...

  8. [记录]Python2.7使用argparse模块

    # -*- coding: utf8 -*- import argparse #ArgumentParser.add_argument(name or flags-[, action][, nargs ...

  9. 一个例子理解break和continue的区别

    结论:break用于终止整个循环,而continue用于终止某一次循环.public class Test { public static void main(String[] args) { for ...

  10. Scrapy-多层爬取天堂图片网

    1.根据图片分类对爬取的图片进行分类 开发者选项 --> 找到分类地址         爬取每个分类的地址通过回调函数传入下一层 name = 'sky'start_urls = ['http: ...