CF #301 (Div. 2) D. Bad Luck Island (概率期望dp)
来源:互联网 发布:网络计算机 编辑:程序博客网 时间:2024/05/11 18:53
The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time.
Input
The single line contains three integers r, s and p (1 ≤ r, s, p ≤ 100) — the original number of individuals in the species of rock, scissors and paper, respectively.
Output
Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn’t exceed 10 - 9.
Examples
input
2 2 2
output
0.333333333333 0.333333333333 0.333333333333
input
2 1 2
output
0.150000000000 0.300000000000 0.550000000000
input
1 1 3
output
0.057142857143 0.657142857143 0.285714285714
大致题意:在一个岛上有r个石头人,s个剪刀人,p个布人,他们每个人碰到的几率都一样,当石头人碰到剪刀人,剪刀人就会死掉,剪刀人碰到布人,布人就会死掉,布人碰到石头人,石头人就会死掉。过了一段时间后,这个岛上只剩下了一个人种,输出这三个种族最后存活下来的概率。
思路:假设dp[i][j][k]表示现在三个种族的人数分别为i,j,k时的概率。那么dp[r][s][p]=1。
第一个人种碰到第二个人种的概率为i*j/(i*j+j*k+i*k)。其余同理。
当前状态dp[i][j][k]可能由以下三种状态转移过来
如果上个状态是石头人死了 dp[i][j][k]+=dp[i+1][j][k]*(石头人碰到布人的概率)
如果上个状态是剪刀人死了 dp[i][j][k]+=dp[i][j+1][k]*(石头人碰到剪刀人的概率)
如果上个状态是布人死了 dp[i][j][k]+=dp[i][j][k+1]*(剪刀人碰到布人的概率)
然后分别将dp[i][0][0],dp[0][i][0],dp[0][0][i]全部加起来即是答案
需要注意的是当某一个人种数量为0时,另一个会被他杀的人种的人数就不会再减少了。(开始没考虑到卡了半天。。。)
代码如下
#include <iostream> #include <cmath>#include <algorithm>#include <cstring>#include <queue>#include <cstdio>#include <map>using namespace std; #define ll long long int double dp[105][105][105];int main() { int a,b,c; memset(dp,0,sizeof(0)); scanf("%d%d%d",&a,&b,&c); dp[a][b][c]=1; for(int i=a;i>=0;i--) for(int j=b;j>=0;j--) for(int k=c;k>=0;k--) { if(i==a&&j==b&&k==c) continue; if(k!=0)//当布人人数为0时,石头人的人数就不会再减少了,所以dp[i][j][k]也就不可能由dp[i+1][j][k]这个状态转移过来,以下同理 dp[i][j][k]+=dp[i+1][j][k]*k*(i+1)*1.0/((i+1)*k+(i+1)*j+j*k); if(i!=0) dp[i][j][k]+=dp[i][j+1][k]*i*(j+1)*1.0/(i*k+i*(j+1)+(j+1)*k); if(j!=0) dp[i][j][k]+=dp[i][j][k+1]*j*(k+1)*1.0/(i*(k+1)+i*j+j*(k+1)); } double s1=0,s2=0,s3=0; for(int i=1;i<=a;i++) s1+=dp[i][0][0]; for(int i=1;i<=b;i++) s2+=dp[0][i][0]; for(int i=1;i<=c;i++) s3+=dp[0][0][i]; printf("%.12lf\n",s1); printf("%.12lf\n",s2); printf("%.12lf\n",s3); return 0; }
- CF #301 (Div. 2) D. Bad Luck Island (概率期望dp)
- cf#301-D - Bad Luck Island-概率dp(水 )
- Codeforces Round #301 (Div. 2) -- D. Bad Luck Island (概率DP)
- Codeforces Round #301 (Div. 2) D. Bad Luck Island(概率DP)
- cf 540D D. Bad Luck Island 概率dp
- CF# 301 D Bad Luck Island(概率dp+记忆化)
- Cf Round #301 (Div. 2) D. Bad Luck Island
- CF 540D. Bad Luck Island 概率dp
- Codeforces Round #301 (Div. 2)---D. Bad Luck Island(概率dp)
- 概率dp Codeforces Round #301 (Div. 2) D - Bad Luck Island
- Codeforces Round #301 (Div. 2)-D. Bad Luck Island(概率dp)
- Codeforces Round #301 (Div. 2) D. Bad Luck Island 概率dp
- codeforces 540D. Bad Luck Island (概率与期望DP)
- #301 (div.2) D. Bad Luck Island
- Codeforces Div.301D Bad Luck Island(概率dp+记忆化搜索)
- CodeForces 540D Bad Luck Island (概率dp)
- [Codeforces540D]Bad Luck Island(概率dp)
- codeforces 540D D. Bad Luck Island( 概率dp)
- 作用域与作用域链
- vs2015\17支持xp程序生成
- bzoj 1756(线段树)
- javaSE入门学习推荐
- swift3 键盘通知事件
- CF #301 (Div. 2) D. Bad Luck Island (概率期望dp)
- Codeforces Round #408 (Div. 2) D.Police Stations【Bfs+思维】
- mysql常用内置函数与所有函数
- 滴滴2017笔试dfs
- DP经典题
- POJ 1094 Sorting It All Out 拓扑排序
- Centos7安装并配置mysql5.6完美教程
- scala之数组
- Swift 3 popup model dialog传递数据