Good Bye 2017 D. New Year and Arbitrary Arrangement
看了别人的题解
首先这题是一个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的更多相关文章
- 【CodeForces】908 D. New Year and Arbitrary Arrangement
[题目]Good Bye 2017 D. New Year and Arbitrary Arrangement [题意]给定正整数k,pa,pb,初始有空字符串,每次有pa/(pa+pb)的可能在字符 ...
- Good Bye 2017 A B C
Good Bye 2017 A New Year and Counting Cards 题目链接: http://codeforces.com/contest/908/problem/A 思路: 如果 ...
- Good Bye 2017 部分题解
D. New Year and Arbitrary Arrangement 分析 \(dp[i][j]\) 表示已有 \(i\) 个 \(a\) 和 \(j\) 个 \(ab\) 的情况下继续构造能得 ...
- Good Bye 2017
太菜了啊,一不小心就goodbye rating了 A. New Year and Counting Cards time limit per test 1 second memory limit p ...
- [Codeforces]Good Bye 2017
A - New Year and Counting Cards #pragma comment(linker, "/STACK:102400000,102400000") #inc ...
- Codeforces 908 D.New Year and Arbitrary Arrangement (概率&期望DP)
题目链接:New Year and Arbitrary Arrangement 题意: 有一个ab字符串,初始为空. 用Pa/(Pa+Pb)的概率在末尾添加字母a,有 Pb/(Pa+Pb)的概率在末尾 ...
- [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 ...
- Hello 2018, Bye 2017
2017年过去了,过去一年经历了太多,改变了好多好多,可以说人生进入了另一个阶段,有可能是成熟吧. 回顾2017 去年换了新工作,离开了将近工作了8年的公司,不带走一丝云彩,为其任劳任怨,最后没有任何 ...
随机推荐
- SpringMVC源码情操陶冶-DispatcherServlet
本文对springmvc核心类DispatcherServlet作下简单的向导,方便博主与读者查阅 DispatcherServlet-继承关系 分析DispatcherServlet的继承关系以及主 ...
- CF 235C. Cyclical Quest [后缀自动机]
题意:给一个主串和多个询问串,求询问串的所有样子不同的周期同构出现次数和 没有周期同构很简单就是询问串出现次数,|Right| 有了周期同构,就是所有循环,把询问串复制一遍贴到后面啊!思想和POJ15 ...
- linux内核链表的使用
linux内核链表:链表通常包括两个域:数据域和指针域.struct list_head{struct list_head *next,*prev;};include/linux/list.h中实现了 ...
- shiro权限控制的简单实现
权限控制常用的有shiro.spring security,两者相比较,各有优缺点,此篇文章以shiro为例,实现系统的权限控制. 一.数据库的设计 简单的五张表,用户.角色.权限及关联表: CREA ...
- VC下防止反汇编的办法(1)
最近在看IDA的书,讲汇编语言的部分提到了一种防止递归向下汇编器逆向程序的方法 这里esp指向栈顶,也就是调用方最后入栈的返回地址.然而实际在VC2017里用内联汇编这么做是不行的,原因可以看看VC生 ...
- Python比较运算符
判断两个对象之间的关系,和条件选择和循环结合使用的 以下假设变量a为10,变量b为20: 示例1:输入三个互不相等的整数,按照从小到大输出 num01,num02,num03 = eval(input ...
- centos 6.* 配置端口
vi /etc/sysconfig/iptables 将 -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT (允 ...
- Git 上传 GitHub
1.下载 2.安装 3.功能识别 3-1.查看git版本 git --version 3-2.移除原来的版本 yum remove git 4.配置 4-1.用户配置信息 git config ...
- thinkphp5判断移动或pc端访问并调用不同模板
废话不多说,直接上代码 先修改\thinkphp\library\think\view\driver\Think.php文件 把 public function __construct($config ...
- 初识vue——起步
一.目录结构: 我们经常使用的是以下几个目录: 1.assets:静态资产文件:在vue组件中,所有组件中,所有模板和CSS都会被vue-html-loader和css-loader解析,并查找资源u ...