【codeforces 148D】 Bag of mice
http://codeforces.com/problemset/problem/148/D (题目链接)
题意
包中有w个白鼠,b个黑鼠。公主和龙轮流画老鼠,公主先画,谁先画到白鼠谁就赢。龙每画完一只老鼠,就会有另一只老鼠从包中跑出来。每只老鼠被画到以及跑出的概率相等,问公主获胜的概率。
Solution
令${f_{0/1,i,j}}$表示此时公主/龙选,包中还剩i只白鼠,j只黑鼠,公主赢的概率。那么转移很显然:
$${f_{0,i,j}=\frac{i}{i+j}+\frac{j}{i+j}*f_{1,i,j-1}}$$
$${f_{1,i,j}=\frac{j}{i+j}*(\frac{i}{i+j-1}*f_{0,i-1,j-1}+\frac{j}{i+j-1}*f_{0,i,j-2})}$$
细节
一个加号没打,看半天没看出来。。
代码
// codeforces148D #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> #include<cmath> #define LL long long #define inf 1<<30 #define Pi acos(-1.0) #define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout); using namespace std; const int maxn=1010; double f[2][maxn][maxn]; int n,m; int main() { scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) f[0][i][0]=1; for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) { f[0][i][j]=(double)(i+j*f[1][i][j-1])/(i+j); f[1][i][j]=(double)(i*f[0][i-1][j-1])/(i+j-1); if (j>1) f[1][i][j]+=(double)((j-1)*f[0][i][j-2])/(i+j-1); f[1][i][j]*=(double)j/(i+j); } printf("%.9lf",f[0][n][m]); return 0; }
【codeforces 148D】 Bag of mice的更多相关文章
- 【Codeforces 105D】 Bag of mice
[题目链接] http://codeforces.com/contest/148/problem/D [算法] 概率DP f[w][b]表示还剩w只白老鼠,b只黑老鼠,公主胜利的概率,那么 : 1. ...
- 【CodeForces】【148D】Bag of mice
概率DP kuangbin总结中的第9题 啊……题目给的数据只有白鼠和黑鼠的数量,所以我们只能在这个上面做(gao)文(D)章(P)了…… 明显可以用两种老鼠的数量来作为状态= = 我的WA做法: 令 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【CF148D】 Bag of mice (概率DP)
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- 【codeforces 793C】Mice problem
[题目链接]:http://codeforces.com/contest/793/problem/C [题意] 给你每个点x轴移动速度,y轴移动速度; 问你有没有某个时刻,所有的点都"严格& ...
- 【42.86%】【codeforces 742D】Arpa's weak amphitheater and Mehrdad's valuable Hoses
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【47.95%】【codeforces 554C】Kyoya and Colored Balls
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【21.58%】【codeforces 746D】Green and Black Tea
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces 148 D Bag of mice
D. Bag of mice http://codeforces.com/problemset/problem/148/D time limit per test 2 seconds memory l ...
随机推荐
- linux(七)__shell脚本编程
一.什么是shell脚本 shell除了是命令解释器之外还是一种编程语言,用shell编写的程序类似于DOS下的批处理程序. 它是用户与操作系统之间的一个接口. shell脚本语言非常擅长处理文本类型 ...
- 实现一个基于 SharePoint 2013 的 Timecard 应用(中)
门户视图 随着 Timecard 列表的增多,如何查找和管理这许多的 Timecard 也就成了问题.尤其对于团队经理而言,他除了自己填写的 Timecard,还要审核团队成员的 Timecard 任 ...
- 长按TextField或TextView显示中文的粘贴复制
首先要确保手机当前系统为中文,只需要在 plist 文件中添加 Localized resources can be mixed = YES 就行了
- [原创]Linux-day1
原创:转发务必注明出处http://www.cnblogs.com/0zcl/p/6077298.html 一.Linux的基本原则 由目的单一的小程序组成:组合小程序完成复杂任务 一切皆文件 尽量避 ...
- docker通过iptables修改或新增镜像映射端口
443 8088 22 端口是初始映射端口 [root@SERVER ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAM ...
- Redis五种基本数据结构
1.字符串 示例: 2.列表 示例: 3.集合 示例: 4.散列 示例: 5.有序集合 待续...
- 分享一下Java写的坦克大战游戏,相信很多人小时候玩过
写在前面 程序是五六年前读书的时候写的,里面会有一些不规范的,我已经将代码传到github上了,有时间会优化修改. 程序运行机制 定义了一个JPanel,然后每隔一小段时间重绘一遍. 重绘的内容如下: ...
- C# dynamic 动态创建 json
1. 如何通过C# 的dynamic 创建如下json 对象? { "query": { "match": [{ "name": " ...
- SQL Server附加数据库报错:无法打开物理文件,操作系统错误5
问题描述: 附加数据时,提示无法打开物理文件,操作系统错误5.如下图: 问题原因:可能是文件访问权限方面的问题. 解决方案:找到数据库的mdf和ldf文件,赋予权限即可.如下图: 找到mdf ...
- 3-linux下部署tomcat应用
linux下部署tomcat应用 相关软件下载 jdk http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downlo ...