codeforces-148D-Bag of mice-概率DP
来源:互联网 发布:母婴cms 编辑:程序博客网 时间:2024/05/14 12:26
dp[x][y]:现在有x个白老鼠,y个黑老鼠,公主赢的概率。
那么:
如果公主直接拿到白老鼠,概率为x/(x+y),公主赢。
如果公主拿到黑老鼠,概率为y/(x+y),那么公主如果想赢,龙必须拿到黑老鼠,概率为(y-1)/(x+y-1);
那么逃跑的老鼠为黑老鼠的概率为(y-2)/(x+y-2),为白老鼠的概率为(x)/(x+y-2);
那么dp[x][y]=x/(x+y)+y/(x+y) * (y-1)/(x+y-1) * ( (y-2)/(x+y-2) * dp[x][y-3] + (x)/(x+y-2) * dp[x-1][y-2] );
记忆化深搜也行,直接递推DP也行。
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<stdlib.h>#include<vector>#include<cmath>#include<queue>#include<set>#include<stack>using namespace std;#define N 100010#define LL long long#define INF 0xfffffff#define maxn 1100double dp[maxn][maxn];double dos(int x,int y){ if(x<0||y<0)return 0; if(x==0)return 0; if(y==0)return 1; if(dp[x][y]>-0.5)return dp[x][y]; double a,b; a=1.0*x; b=1.0*y; dp[x][y]=a/(a+b); if(x+y>=3) { dp[x][y]+=(b*(b-1)/((a+b)*(a+b-1)))* (dos(x-1,y-2)*a/(a+b-2)+dos(x,y-3)*(b-2)/(a+b-2)); } // cout<<x<<" "<<y<<" "<<dp[x][y]<<endl; return dp[x][y];}int main(){ int a,b; while(~scanf("%d%d",&a,&b)) { memset(dp,-1,sizeof(dp)); printf("%.10lf\n",dos(a,b)); } return 0;}
0 0
- Codeforces 148D D Bag of mice(概率dp)
- codeforces 148D D. 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 148 D Bag of mice(概率dp)
- codeforces 148 D. Bag of mice(概率dp)
- codeforces 148 D. 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 , DFS
- Codeforces 148D Bag of mice(概率dp)
- CodeForces 148D Bag of mice 概率dp!!
- Codeforces 148D Bag of mice(概率dp)
- CodeForces 148D. Bag of mice(概率dp啊 )
- Bag of mice - CodeForces 148 D 概率dp
- Ubuntu下创建用户并创建家目录
- OCP 1Z0 052 159
- C\C++控制台程序隐藏方法总结
- MAC 如何强制关闭程序
- CentOS6.5安装MySQL5.5
- codeforces-148D-Bag of mice-概率DP
- android:layout_gravity和android:gravity的区别
- YUV内存里的存放顺序
- Yii2.0实用功能技巧解密之——布局文件多变量继承(嵌套、引用)终极功能
- 矩阵的旋转
- 第6条:消除过期的引用对象
- 自连接
- App上线流程全攻略(史上最详细步骤)
- 有关微信公众平台和html5的想法