CF #301 (Div. 2) D. Bad Luck Island (概率期望dp)

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;  
}  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值