【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$个白老鼠 ...
随机推荐
- JS中数组那些事~
今天闲的没事,看了一些关于数组的操作,好久木有用过,很多都已经忘记的差不多了,所以今天花了一个小时写了一些demo,准备备份一下方便以后使用~~~ 下面是一些工作当中,经常用到的数组的方法,小伙伴可以 ...
- 使用转义防御XSS
使用转义防御XSS 在输出的时候防御XSS即对用户输入进行转义,XSS的问题本质上还是代码注入,HTML或者javascript的代码注入,即混淆了用户输入的数据和代码.而解决这个问题,就需要根据用户 ...
- 【NOIP题解】NOIP2017 TG D2T3 列队
列队,NOIP2017 TG D2T3. 树状数组经典题. 题目链接:洛谷. 题意: Sylvia 是一个热爱学习的女孩子. 前段时间,Sylvia 参加了学校的军训.众所周知,军训的时候需要站方阵. ...
- TcxScheduler的使用2
DevExpress 行事历(Scheduler)的常用属性.事件和方法 参考资料来源:附带的ExpressScheduler 2 Demo, 如想了解更多可以查看Demo. 一.TcxSchedu ...
- 理解 Linux 的硬链接与软链接(待研究)
从 inode 了解 Linux 文件系统 硬链接与软链接是 Linux 文件系统中的一个重要概念,其涉及文件系统中的索引节点 (index node 又称 inode),而索引节点对象是 Linux ...
- shell 数组基础->
数组其实也算是变量, 传统的变量只能存储一个值, 但数组可以存储多个值. 普通数组:只能使用整数 作为数组索引 [有序 0 1 2 3 4 ]关联数组:可以使用字符串 作为数组索引 [无序 name ...
- Gitlab权限管理
使用管理员登陆gitlab(版本为8.9)创建一个组 给用户授权 创建新用户 再创建两个dev1和dev2 然后再到项目界面授权给pm授权master 创建库(事先先建一个java组) 设置权限 创建 ...
- poj1102
模拟 #include <iostream> #include <string> using namespace std; ][][] = { { ' ', '-', ' ', ...
- python基础--面向对象
什么是面向对象编程 OOP编程是利用“类”和对象来创建各种模型来实现对真实世界的描述. OOP具有可维护性和可扩展性 二:面向对象有那些特性 1)CLASS类:一个类是对拥有相同属性的对象的抽象.类拥 ...
- tf.nn.embedding_lookup函数
tf.nn.embedding_lookup(params, ids, partition_strategy='mod', name=None, validate_indices=True, max_ ...