CodeForces - 148D Bag of mice
2017-01-06 14:02
155 查看
http://codeforces.com/problemset/problem/148/D
题目大意:
原来袋子里有w只白鼠和b只黑鼠
龙和王妃轮流从袋子里抓老鼠。谁先抓到白色老鼠谁就赢。
王妃每次抓一只老鼠,龙每次抓完一只老鼠之后会有一只老鼠跑出来。
每次抓老鼠和跑出来的老鼠都是随机的。
如果两个人都没有抓到白色老鼠则龙赢。王妃先抓。
问王妃赢的概率。
(0 ≤ w, b ≤ 1000).
题解:
其中第一行表示为王妃拿到的白色老鼠,自然是直接退出了
第二行表示为王妃拿到了黑色老鼠,但是因为不能让龙赢,所以龙必须要抓到黑色老鼠
那么就应该讨论龙抓完后跑出来的是黑色老鼠还是白色老鼠
即为对应的2、3两行
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; inline void read(int &x){ x=0;char ch;bool flag = false; while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true; while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x; } inline int cat_max(const int &a,const int &b){return a>b ? a:b;} inline int cat_min(const int &a,const int &b){return a<b ? a:b;} const int maxn = 1024; double f[maxn][maxn]; int main(){ int n,m;read(n);read(m); for(int i=0;i<=n;++i) f[i][0] = 1.0; for(int i=0;i<=m;++i) f[0][i] = 0.0; for(int i=1;i<=n;++i){ for(int j=1;j<=m;++j){ f[i][j] = (double)i/(i+j); if(j-3>=0) f[i][j] += (double)j/(i+j)*(j-1)/(i+j-1)*(j-2)/(i+j-2)*f[i][j-3]; if(j-2>=0) f[i][j] += (double)j/(i+j)*(j-1)/(i+j-1)*i/(i+j-2)*f[i-1][j-2]; } }printf("%.9lf\n",f [m]); getchar();getchar(); return 0; }
相关文章推荐
- CodeForces 148D Bag of mice [概率DP]
- CodeForces 148D Bag of mice
- CodeForces 148D Bag of Mice 概率DP
- Codeforces 148D Bag of mice(概率dp)
- CodeForces 148D Bag of mice
- Codeforces 148D Bag of mice (概率dp)
- codeforces 148D Bag of mice(概率dp)
- CodeForces 148D Bag of mice(概率DP )
- CodeForces 148D Bag of mice 详解 (概率DP)
- Codeforces 148D Bag of mice:概率dp 记忆化搜索
- CodeForces 148D Bag of mice 概率DP
- CodeForces - 148D Bag of mice(概率dp)
- CodeForces 148D Bag of mice(概率DP)
- codeforces148D Bag of mice
- CodeForces 148D Bag of mice
- Codeforces-148D Bag of mice (概率DP)
- Codeforces 148D Bag of mice
- Codeforces 148D Bag of mice 概率dp(水
- Codeforces 148D Bag of mice 概率dp(水
- CodeForces - 148D Bag of mice(动态规划)