codeforce 148D. Bag of mice[概率dp]】的更多相关文章

D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard 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 t…
设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)/(…
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard 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 t…
题意:给你w个白色小鼠和b个黑色小鼠,把他们放到袋子里,princess先取,dragon后取,princess取的时候从剩下的当当中任意取一个,dragon取得时候也是从剩下的时候任取一个,但是取完之后会随机跳出来一个.取到每个小鼠的概率是一样的,跳出的也是一样的.先取到白色的小鼠赢,问最后princess能赢的概率. 思路:概率dp,如果把princess能赢的分成两种情况,那么这个题就是递推了,我是用记忆化搜索写的.首先,用dp[i][j]表示袋子当中还有i个白色的,j个黑色的prince…
题目链接:http://codeforces.com/problemset/problem/148/D 题意: 原来袋子里有w仅仅白鼠和b仅仅黑鼠 龙和王妃轮流从袋子里抓老鼠. 谁先抓到白色老师谁就赢. 王妃每次抓一仅仅老鼠.龙每次抓完一仅仅老鼠之后会有一仅仅老鼠跑出来. 每次抓老鼠和跑出来的老鼠都是随机的. 假设两个人都没有抓到白色老鼠则龙赢.王妃先抓. 问王妃赢的概率. 解析: 设dp[i][j]表示如今轮到王妃抓时有i仅仅白鼠,j仅仅黑鼠.王妃赢的概率 明显 dp[0][j]=0,0<=j…
除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃圾,大哥拿来了一袋老鼠,其中有w只白老鼠和b只黑老鼠.胡小兔先抓,先抓到白老鼠的人赢. 每次学姐抓完老鼠之后,总会有另外一只老鼠从袋子里自己跑出来(这只老鼠不算任何人抓的),而胡小兔抓老鼠时则不会发生这样的事. 每次袋子里的每只老鼠被抓到的概率相等,当有一只老鼠跑出来的时候,每只老鼠跑出来的几率也相…
Bag of mice  CodeForces - 148D 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…
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard 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 t…
题目链接: http://codeforces.com/problemset/problem/148/D D. Bag of mice time limit per test2 secondsmemory limit per test256 megabytes 问题描述 The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the…
http://codeforces.com/contest/148/problem/D 题目意思是龙和公主轮流从袋子里抽老鼠.袋子里有白老师 W 仅仅.黑老师 D 仅仅.公主先抽,第一个抽出白老鼠的胜利,龙每次抽的时候会随机跑出一仅仅老鼠.给出W和D要你求出公主胜利的概率. 对于dp[w][d]表示有w仅仅白老鼠d仅仅黑老鼠的情况下公主胜利的概率,假设公主第一次就抽出白鼠,概率是 w/(w+d) .而假设公主没有抽到白鼠,要让公主胜利,龙也不能抽到白鼠.则是 rec = d/(w+d) * (d…
Link: http://codeforces.com/problemset/problem/148/D Refer to: http://www.cnblogs.com/kuangbin/archive/2012/10/04/2711184.html #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #incl…
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes Promblem description   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 danci…
题面 这是我做的第一道概率DP题: 做完后发现没有后效性的DP是真的水: 在这里说主要是再捋顺一下思路: 设f[i][j]表示有i只白鼠,j只黑鼠是获胜的概率: 显然:f[i][0]=1; 然后分四种情况: 1.先手刚好拿到白鼠:概率是i/(i+j); 2.先手拿到黑鼠,后手拿到了白鼠:概率为0: 3.先手拿到了黑鼠,后手拿到了也黑鼠,并且跑的是白鼠:概率是::dp[i][j]=j/(i+j)∗(j−1)/(i+j−1)∗i/(i+j−2)∗dp[i−1][j−2]; 4.先手拿到了黑鼠,后手拿…
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard 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…
题目链接:http://codeforces.com/problemset/problem/148/D 题意: 一个袋子中有w只白老鼠,b只黑老鼠. 公主和龙轮流从袋子里随机抓一只老鼠出来,不放回,公主先拿. 公主每次抓一只出来.龙每次在抓一只出来之后,会随机有一只老鼠跳出来(被龙吓的了...). 先抓到白老鼠的人赢.若两人最后都没有抓到白老鼠,则龙赢. 问你公主赢的概率. 题解: 表示状态: dp[i][j] = probability to win(当前公主先手,公主赢的概率) i:剩i只白…
传送门 # 解题思路 ​    ~~这怕是本蒟蒻第一个独立做出来的期望$dp$的题,发篇题解庆祝一下~~.首先,应该是能比较自然的想出状态设计$f[i][j][0/1]$ 表示当前还剩 $i$个白老鼠,$j$个黑老鼠,当前是$A/B$抓的概率.有个问题似乎因为当其中一个人抓到白老鼠时游戏就结束了,而在转移过程中比较难表示出来这个,但换状态的话比较难转移.所以要想一个办法,因为如果知道当前有$i$只白老鼠和$j$只黑老鼠的话,那么当前人获胜的概率可以$O(1)$的算出来,$p=\dfrac {i}…
http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次抓一只老鼠,龙每次抓完一只老鼠之后会有一只老鼠跑出来. 每次抓老鼠和跑出来的老鼠都是随机的. 如果两个人都没有抓到白色老鼠则龙赢.王妃先抓. 问王妃赢的概率. (0 ≤ w, b ≤ 1000). 题解: 其中第一行表示为王妃拿到的白色老鼠,自然是直接退出了 第二行表示为王妃拿到了黑色老鼠,但是因为…
http://codeforces.com/problemset/problem/148/D 题意:w个白b个黑,公主和龙轮流取,公主先取,等概率取到一个.当龙取完后,会等概率跳出一只.(0<=w, b<=1000) #include <bits/stdc++.h> using namespace std; int n, m; const int N=1005; double d[N][N][2]; int main() { scanf("%d%d", &…
概率类题目一直比较弱,准备把kuangbin大师傅总结的这篇题刷一下! 我把下面的代码换成了自己的代码! 原文地址:http://www.cnblogs.com/kuangbin/archive/2012/10/02/2710606.html *************************************************************** 概率DP主要用于求解期望.概率等题目. 转移方程有时候比较灵活. 一般求概率是正推,求期望是逆推.通过题目可以体会到这点. 首先…
POJ 3744 Scout YYF I 这就是一个乱搞题,暴力发现TLE了,然后看了看discuss里说可以矩阵加速,想了一会才想明白怎么用矩阵,分着算的啊.先算f[num[i]-1]之类的,代码太长了,还是找找规律吧.. #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <algorithm> #include <vector…
题目链接 D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mounta…
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard 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 t…
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard 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 t…
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard 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 t…
http://codeforces.com/problemset/problem/148/D D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The dragon and the princess are arguing about what to do on the New Year's Eve…
概率DP kuangbin总结中的第9题 啊……题目给的数据只有白鼠和黑鼠的数量,所以我们只能在这个上面做(gao)文(D)章(P)了…… 明显可以用两种老鼠的数量来作为状态= = 我的WA做法: 令f[i][j]表示从(w,b)轮流取老鼠一直到(i,j)[此时轮process取]两人一直不分胜负的概率,很明显(i,j)这个状态下赢的概率为 i / (i+j) ,那么总共赢的概率就是对所有(i,j),f[i][j]*i/(i+j)求和 转移当然很简单啦~ f[i][j]只可能从f[i][j+3]…
题意: 原来袋子里有w仅仅白鼠和b仅仅黑鼠 龙和王妃轮流从袋子里抓老鼠. 谁先抓到白色老师谁就赢. 王妃每次抓一仅仅老鼠,龙每次抓完一仅仅老鼠之后会有一仅仅老鼠跑出来. 每次抓老鼠和跑出来的老鼠都是随机的. 假设两个人都没有抓到白色老鼠则龙赢.王妃先抓. 问王妃赢的概率. 第一次写的时候还是出问题了,还是对概率DP理解有问题: 当前状态满足条件的概率=segma(转移到状态si的概率pi * 状态i满足条件的概率) 但是一定要枚举出来全部可能转移的状态,并且仅仅考虑一步.就是说考虑一个游戏回合之…
题目大意:美女与野兽在玩画鸽子的游戏.鸽子在用黑布遮住的笼子里,白色的有w只,黑色的有b只,每次拿出一只作画,谁先画到白色的鸽子谁就赢.美女首先画,因为野兽太丑,它每次画的时候都会吓跑一只鸽子,所有出笼子的鸽子都不在进去.求美女赢得概率.(设定假如没有人画到白色鸽子,算野兽赢). 题目分析:这道题不难,很显然的概率DP.这是我第一次写概率DP,纪念一下... 代码如下: # include<iostream> # include<cstdio> # include<vecto…
数学期望 P=Σ每一种状态*对应的概率. 因为不可能枚举完所有的状态,有时也不可能枚举完,比如抛硬币,有可能一直是正面,etc.在没有接触数学期望时看到数学期望的题可能会觉得很阔怕(因为我高中就是这么认为的,对不起何老板了QwQ),避之不及. 但是现在发现大多数题就是手动找公式或者DP推出即可,只要处理好边界,然后写好方程,代码超级简短.与常规的求解不同,数学期望经常逆向推出. 比如常规的dp[x]可能表示到了x这一状态有多少,最后答案是dp[n].而数学期望的dp[x]一般表示到了x这一状态还…
Bag of mice 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 de…