概率DP——D - Bad Luck Island CodeForces - 540D 石头人,剪刀人,布人

博客目录

返回二级目录——kaugnbin概率dp习题集

一、原题

题目传送门

The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors andp 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 rs 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人.

每次会有两个不同阵营的人见面,然后一个人可能会被kill。

问最终三个队获胜的几率。

一个队获胜意味着其他队的人都死了。

(翻译来自互联网)

三、分析

很明显的概率dp,

 

  • 设状态dp[i][j][k]表示r,s,p三种人剩下i,j,k个时的概率。所以dp[r][s][p]=1
  • 状态转移:

          (我为人人式转移)

            设p1表示当前状态下,i和j相遇的概率(也就是i吃掉j),由概率知识得p1=(i*j)/(i*j+j*k+k*i)

            同理设p2表示j和k相遇的概率,p3表示k和i相遇的概率

            根据全概率公式:

            dp[i-1][j][k]=p1*dp[i][j][k];

            (j-1)和(k-1)同理

 

  • 边界条件:初始化为dp[][][]=0,dp[r][s][k]=1;   特殊考虑rsk中某一个和某两个不存在的情况,具体看代码吧说不清。

四、AC代码

#include<bits/stdc++.h>
using namespace std;
double dp[110][110][110];
int main()
{
	int r,s,p;
	cin>>r>>s>>p;
	dp[r][s][p]=1;
	int i,j,k;
	for(i=r;i>=0;i--)
		for(j=s;j>=0;j--)
			for(k=p;k>=0;k--)
				if(!!i+!!j+!!k>=2)
				{
					if(i)
						dp[i-1][j][k]+=(k*i)/(double)(i*j+j*k+k*i)*dp[i][j][k];
					if(j)
						dp[i][j-1][k]+=(i*j)/(double)(i*j+j*k+k*i)*dp[i][j][k];
					if(k)
						dp[i][j][k-1]+=(j*k)/(double)(i*j+j*k+k*i)*dp[i][j][k];
				}
				else
				{
					if(i>1)
						dp[1][0][0]+=dp[i][j][k];
					else if(j>1)
						dp[0][1][0]+=dp[i][j][k];
					else if(k>1)
						dp[0][0][1]+=dp[i][j][k];
				}
	printf("%.10lf %.10lf %.10lf\n",dp[1][0][0],dp[0][1][0],dp[0][0][1]);
}

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值