【CF148D】 Bag of mice (概率DP)
D. Bag of micetime limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chance.
They take turns drawing a mouse from a bag which initially contains w white and b black mice. The person who is the first to draw a white mouse wins. After each mouse drawn by the dragon the rest of mice in the bag panic, and one of them jumps out of the bag itself (the princess draws her mice carefully and doesn't scare other mice). Princess draws first. What is the probability of the princess winning?
If there are no more mice in the bag and nobody has drawn a white mouse, the dragon wins. Mice which jump out of the bag themselves are not considered to be drawn (do not define the winner). Once a mouse has left the bag, it never returns to it. Every mouse is drawn from the bag with the same probability as every other one, and every mouse jumps out of the bag with the same probability as every other one.
InputThe only line of input data contains two integers w and b (0 ≤ w, b ≤ 1000).
OutputOutput the probability of the princess winning. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 9.
Examplesinput1 3output0.500000000input5 5output0.658730159NoteLet's go through the first sample. The probability of the princess drawing a white mouse on her first turn and winning right away is 1/4. The probability of the dragon drawing a black mouse and not winning on his first turn is 3/4 * 2/3 = 1/2. After this there are two mice left in the bag — one black and one white; one of them jumps out, and the other is drawn by the princess on her second turn. If the princess' mouse is white, she wins (probability is 1/2 * 1/2 = 1/4), otherwise nobody gets the white mouse, so according to the rule the dragon wins.
【分析】
跟前面红黑那题差不多。
f[p][i][j]表示现在是p选,已经没了i个白,j个黑,p胜的概率。
然后随便转化一下就好?
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define Maxn 1010 double f[][Maxn][Maxn]; int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=n;i>=;i--)
for(int j=m;j>=;j--)
{
if(i==n) f[][i][j]=f[][i][j]=;
else if(j==m) f[][i][j]=f[][i][j]=;
else
{
if(j+==m) f[][i][j]=1.0*(n-i)/(n+m-i-j)+1.0*(m-j)/(n+m-i-j)*(-f[][i+][j+]);
else
{
f[][i][j]=1.0*(n-i)/(n+m-i-j)+1.0*(m-j)/(n+m-i-j)*((-f[][i+][j+])*(n-i)/(n+m-i-j-)+(-f[][i][j+])*(m-j-)/(n+m-i-j-));
}
f[][i][j]=1.0*(n-i)/(n+m-i-j)+1.0*(m-j)/(n+m-i-j)*(-f[][i][j+]);
}
}
printf("%.9lf\n",f[][][]);
return ;
}
2017-04-21 19:19:06
【CF148D】 Bag of mice (概率DP)的更多相关文章
- Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题
除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...
- 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 难度:0
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Bag of mice(概率DP)
Bag of mice CodeForces - 148D The dragon and the princess are arguing about what to do on the New Y ...
- 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)
题意:给你w个白色小鼠和b个黑色小鼠,把他们放到袋子里,princess先取,dragon后取,princess取的时候从剩下的当当中任意取一个,dragon取得时候也是从剩下的时候任取一个,但是取完 ...
- Codeforces 148D Bag of mice 概率dp(水
题目链接:http://codeforces.com/problemset/problem/148/D 题意: 原来袋子里有w仅仅白鼠和b仅仅黑鼠 龙和王妃轮流从袋子里抓老鼠. 谁先抓到白色老师谁就赢 ...
- 抓老鼠 codeForce 148D - Bag of mice 概率DP
设dp[i][j]为有白老鼠i只,黑老鼠j只时轮到公主取时,公主赢的概率. 那么当i = 0 时,为0 当j = 0时,为1 公主可直接取出白老鼠一只赢的概率为i/(i+j) 公主取出了黑老鼠,龙必然 ...
- Codeforces Round #105 D. Bag of mice 概率dp
http://codeforces.com/contest/148/problem/D 题目意思是龙和公主轮流从袋子里抽老鼠.袋子里有白老师 W 仅仅.黑老师 D 仅仅.公主先抽,第一个抽出白老鼠的胜 ...
- CF148D Bag of mice (期望dp)
传送门 # 解题思路 ~~这怕是本蒟蒻第一个独立做出来的期望$dp$的题,发篇题解庆祝一下~~.首先,应该是能比较自然的想出状态设计$f[i][j][0/1]$ 表示当前还剩 $i$个白老鼠 ...
随机推荐
- nc使用笔记
netcat是网络工具中的瑞士军刀,它能通过TCP和UDP在网络中读写数据.通过与其他工具结合和重定向,你可以在脚本中以多种方式使用它. 现内网中有两台机器:Mac: 192.168.1.109 Ka ...
- zzd 的割草机(Lawnmower)
评测传送门 [题目描述] 已知花坛为一个 n * m 的矩形,草只会长在某些个格子上,zzd 有一个割草机,一开始,zzd 站在(1,1)处,面向(1,m)(面向右).每次 zzd 有两个选择(耗费一 ...
- Python练习-猜年龄的LowB游戏
Alex大神今天让我做一个猜年龄的游戏: 第一个游戏是你只能猜三次:真的很LowB啊~ # 编辑者:闫龙 #猜年龄游戏,3次后程序自动退出! ages = 29; #for循环3次 for i in ...
- 洛谷 P3835: 【模板】可持久化平衡树
题目传送门:洛谷P3835. 题意简述: 题面说的很清楚了. 题解: 考虑建立一棵每个节点都表示一个版本的树. 以初始版本 \(0\) 为根.对于第 \(i\) 个操作,从 \(v_i\) 向 \(i ...
- 【codeforces】【比赛题解】#948 CF Round #470 (Div.2)
[A]Protect Sheep 题意: 一个\(R*C\)的牧场中有一些羊和一些狼,如果狼在羊旁边就会把羊吃掉. 可以在空地上放狗,狼不能通过有狗的地方,狼的行走是四联通的. 问是否能够保护所有的羊 ...
- weight decay(权值衰减)、momentum(冲量)和normalization
一.weight decay(权值衰减)的使用既不是为了提高你所说的收敛精确度也不是为了提高收敛速度,其最终目的是防止过拟合.在损失函数中,weight decay是放在正则项(regularizat ...
- verilog中wire与reg类型的区别
每次写verilog代码时都会考虑把一个变量是设置为wire类型还是reg类型,因此把网上找到的一些关于这方面的资料整理了一下,方便以后查找. wire表示直通,即只要输入有变化,输出马上无条件地反映 ...
- pre,html转义,abbr缩写,表格table
<pre></pre>预定义文本标签pre(保留换行和空格) <sdds>对html转义 <abbr title="sddsdsds"&g ...
- OpenFlow1.3协议wireshark抓包分析
OpenFlow v1.0 v1.0协议消息列表如下: 分为三类消息:Controller-to-switch,asynchronous和symmertric. v1.0(包含至少一个流表,每个流表包 ...
- python网络编程-socket发送大数据包问题
一:什么是socket大数据包发送问题 socket服务器端或者客户端在向对方发送的数据大于对方接受的缓存时,会出现第二次接受还接到上次命令发送的结果.这就出现象第一次接受结果不全,第二次接果出现第一 ...