抓老鼠 codeForce 148D - Bag of mice 概率DP
设dp[i][j]为有白老鼠i只,黑老鼠j只时轮到公主取时,公主赢的概率。
那么当i = 0 时,为0
当j = 0时,为1
公主可直接取出白老鼠一只赢的概率为i/(i+j)
公主取出了黑老鼠,龙必然也要取出黑老鼠公主才能赢,跑出来的老鼠有两种可能
跑出来的是黑老鼠,公主赢的概率为dp[i][j] += j/(i+j)*(j-1)/(i+j-1)*(j-2)/(i+j-2)*dp[i][j-3].(j>=3)
跑出来的是白老鼠,公主赢的概率为dp[i][j] += j/(i+j)*(j-1)/(i+j-1)*i/(i+j-2)*dp[i-1][j-2].(j>=2)
贴代码:
#include <cstdio>
#define N 1005
double dp[N][N];
int main()
{
// freopen("in.c","r",stdin);
int w,b;
scanf("%d%d",&w,&b);
for(int i=; i<=w; ++i) dp[i][] =;
for(int i=; i<=b; ++i) dp[][i] =;
for(int i=; i<=w; ++i)
{
for(int j=; j<=b; ++j)
{
dp[i][j] = (double)i/(i+j);
if(j >= ) dp[i][j] += (double)j/(i+j)*(double)(j-)/(i+j-)*(double)(j-)/(i+j-)*dp[i][j-];
if(j >= ) dp[i][j] += (double)j/(i+j)*(double)(j-)/(i+j-)*(double)i/(i+j-)*dp[i-][j-];
}
}
printf("%.9lf\n",dp[w][b]);
return ;
}
抓老鼠 codeForce 148D - Bag of mice 概率DP的更多相关文章
- codeforce 148D. Bag of mice[概率dp]
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Codeforces 148D Bag of mice 概率dp(水
题目链接:http://codeforces.com/problemset/problem/148/D 题意: 原来袋子里有w仅仅白鼠和b仅仅黑鼠 龙和王妃轮流从袋子里抓老鼠. 谁先抓到白色老师谁就赢 ...
- CF 148D Bag of mice 概率dp 难度:0
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- codeforces 148D Bag of mice(概率dp)
题意:给你w个白色小鼠和b个黑色小鼠,把他们放到袋子里,princess先取,dragon后取,princess取的时候从剩下的当当中任意取一个,dragon取得时候也是从剩下的时候任取一个,但是取完 ...
- Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题
除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...
- Bag of mice(概率DP)
Bag of mice CodeForces - 148D The dragon and the princess are arguing about what to do on the New Y ...
- Codeforces Round #105 (Div. 2) D. Bag of mice 概率dp
题目链接: http://codeforces.com/problemset/problem/148/D D. Bag of mice time limit per test2 secondsmemo ...
- CF 148D. Bag of mice (可能性DP)
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #105 D. Bag of mice 概率dp
http://codeforces.com/contest/148/problem/D 题目意思是龙和公主轮流从袋子里抽老鼠.袋子里有白老师 W 仅仅.黑老师 D 仅仅.公主先抽,第一个抽出白老鼠的胜 ...
随机推荐
- ubuntu server 无线网卡的处理
1) iwconfig 确定一下接口的名称 2) 编辑 /etc/network/interfaces 加入下面的代码 auto wlan0 iface wlan0 inet dhcp wpa-ssi ...
- Netty优雅退出机制和原理
1.进程的优雅退出 1.1.Kill -9 PID带来的问题 在Linux上通常会通过kill -9 pid的方式强制将某个进程杀掉,这种方式简单高效,因此很多程序的停止脚本经常会选择使用kill - ...
- Oracle性能诊断艺术-学习笔记(索引访问方式)
环境准备: 1.0 测试表 CREATE TABLE t ( id NUMBER, d1 DATE, n1 NUMBER, n2 NUMBER, n3 NUMBER, n4 NUMBER, n5 NU ...
- Spring boot 嵌入的tomcat不能启动: Unregistering JMX-exposed beans on shutdown
原因是:没有引入tomcat依赖包 <dependency> <groupId>org.springframework.boot</groupId> <art ...
- 使用tomcat启动dubbo项目
首先,黑体标出 官方不推荐使用web容器进行dubbo的启动 但是,有些时候,我们不采用他们的建议. 背景: 之前用的dubbo项目,是由main函数启动的,每次发布项目,需要启动两项: 1. tom ...
- 文件属性,获取,设置文件属性chown stat函数
转载:http://c.biancheng.net/cpp/html/326.html man 2 stat查看手册 int stat(const char *path, struct stat *b ...
- memory prefix retro,re out 2
1● retro retr əu 向后,倒退 2● re 重新,一再, 不,反向后
- String对象中的正则表达式
(1)身份证号码验证身份证号码是18位数字,根据GB11643-1999<公民身份证>定义制作:由17位本体码和一位校验码组成.身份证号码前6位是地址码,按(GB/T2260)规定执行.接 ...
- Allow Zero Length 允许空字符串 ACCESS
http://www.360doc.com/content/11/0118/20/991597_87447868.shtml https://microsoft.public.data.ado.nar ...
- Microsoft Jet 数据库引擎 SQL 和 ANSI SQL 的比较
http://westlife063.blog.163.com/blog/static/129942096201052591210384/ Microsoft Jet 数据库引擎 SQL 和 AN ...