Codeforces 540 D Bad Luck Island

Discription

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.

Example

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

方程的转移比较显然23333,问题是怎么消除后效性。    也就是,每次f[i][j][k] 有 (C(i,2) + C(j,2) + C(k,2))/C(i+j+k,2) 的概率走到自己,那么我们用一下生成函数(1+p+p^2+...=1/(1-p))的基本性质就可以算出期望走多少次f[i][j][k],然后再转移即可。
#include<bits/stdc++.h>
#define ll long long
#define D double
using namespace std;
D f[105][105][105];
int n,m,k,C[355];

inline void init(){
	C[0]=C[1]=0;
	for(int i=2;i<=320;i++) C[i]=C[i-1]+i-1;
}

inline void dp(){
	f[n][m][k]=1.00;
	for(int i=n;i>=0;i--)
	    for(int j=m;j>=0;j--)
	        for(int u=k;u>=0;u--) if((i>0)+(j>0)+(u>0)>=2){
	        	f[i][j][u]=f[i][j][u]*C[i+j+u]/(double)(C[i+j+u]-C[i]-C[j]-C[u]);
	        	if(i) f[i-1][j][u]+=f[i][j][u]*i*u/(double)C[i+j+u];
	        	if(j) f[i][j-1][u]+=f[i][j][u]*i*j/(double)C[i+j+u];
	        	if(u) f[i][j][u-1]+=f[i][j][u]*j*u/(double)C[i+j+u];
			}
}

inline void output(){
	D ans;
	ans=0;
	for(int i=1;i<=n;i++) ans+=f[i][0][0];
	printf("%.11lf ",ans);
	ans=0;
	for(int i=1;i<=m;i++) ans+=f[0][i][0];
	printf("%.11lf ",ans);
	ans=0;
	for(int i=1;i<=k;i++) ans+=f[0][0][i];
	printf("%.11lf",ans);
}

int main(){
	init();
	scanf("%d%d%d",&n,&m,&k);
	dp();
	output();
	return 0;
}

  

 

原文地址:https://www.cnblogs.com/JYYHH/p/8597359.html

时间: 2024-10-06 03:04:41

Codeforces 540 D Bad Luck Island的相关文章

Codeforces Div.301D Bad Luck Island(概率dp+记忆化搜索)

一道概率dp问题. 题目链接:http://codeforces.com/contest/540/problem/D 题目大意:一个岛上有r个石头,s个剪子,p个布,他们之间随机挑出两个相遇,如果不是相同物种,就会有一个消失,分别求出最后这座岛上只剩下一个物种的概率. 我们用dp[i][j][k]来存储i个石头,j个剪刀,k个布时,某物种的存活概率,共dp三次,算出三个物种分别的概率. 首先,我们需要把对应想求的物种概率初始化,这里以石头为例,那么对于i从1到r,不难理解dp[i][0][0]=

[Codeforces Round #301 (Div. 2) D]Bad Luck Island(概率Dp)

Description 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, t

Codeforces Round #301 (Div. 2) D. Bad Luck Island 概率DP

D. Bad Luck Island 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 spe

cf 540D D. Bad Luck Island 概率dp

D. Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two

CF#301 D:Bad Luck Island (概率dp)

D:Bad Luck Island 一个岛上有r个石头,s个剪子,p个布,他们之间随机挑出两个相遇,如果不是相同物种,就会有一个消失,分别求出最后这座岛上只剩下一个物种的概率. 我们用dp[i][j][k]来存储剩下 i 个石头, j 个剪刀,k 个布时的概率,共dp三次: 如果石头与剪刀碰面,概率是 p1 = i*j / (i*j+j*k+k*i),这种情况下,剪刀会被石头吃掉,所以石头的数目减少1,表现出来是dp[i-1][j][k] = p1*dp[i][j][k]  (dp的3的返回值均

CF 301div2 D. Bad Luck Island

D. Bad Luck Island 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 spe

Codeforces 540D Bad Luck Island

http://codeforces.com/problemset/problem/540/D 题目大意: 会出石头.剪刀.布的人分别有r,s,p个,他们相互碰到的概率相同,输的人死掉,问最终活下去的人是三种类型的概率. 思路: f[i][j][k]代表i个石头,j个剪刀,k个布状态的概率,初始f[n][m][K]=1 1 #include<cstdio> 2 #include<cmath> 3 #include<algorithm> 4 #include<cstr

CodeForces 540D Bad Luck Island 概率dp

CodeForces 540D 应该是简单概率dp,由于写得少显得十分蠢萌 求期望逆推,求概率正推,大概是这么个意思,贴一发留恋 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define db double const int maxn=108; db dp[maxn][maxn][maxn]; int main() { int i,j,n,m,k,p; whi

「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)

题意与分析(CodeForces 540D) 代码 #include <iomanip> #include <iostream> #include <cstring> #include <algorithm> #include <vector> #define MP make_pair #define PB push_back #define fi first #define se second #define ZERO(x) memset((x