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 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

题意:

  

  给你剪刀石头布三个种类的数量,每次随机两个,问你最后分别剩下这三个的概率

题解:

  假设我们已知数量分别为a,b,c的概率即等于dp[a][b][c];

  那么我们可以得到的是dp[a][b][c-1] 、dp[a][b-1][c] 、 dp[a-1][b][c];

  暴力推下去就得解

#include<bits/stdc++.h>
using namespace std;
const int N = 1e2+20, M = 1e6+10, mod = 1e9+7, inf = 1e9+1000;
typedef long long ll;

double dp[N][N][N];
double a,b,c;
int main() {
    int r,s,p;
    scanf("%d%d%d",&r,&s,&p);
    dp[r][s][p] = 1;
    for(int i=r;i>=0;i--) {
        for(int j=s;j>=0;j--) {
            for(int k=p;k>=0;k--) {
                double all = i*1.0*j+j*1.0*k+k*1.0*i;
                if(all==0) continue;
                if(k-1>=0)dp[i][j][k-1] += dp[i][j][k]*(double)(j*1.0*k)/all;
                if(j-1>=0)dp[i][j-1][k] += dp[i][j][k]*(double)(j*1.0*i)/all;
                if(i-1>=0)dp[i-1][j][k] += dp[i][j][k]*(double)(i*1.0*k)/all;
            }
        }
    }
    for(int i=1;i<=r;i++) a+=dp[i][0][0];
    for(int i=1;i<=s;i++) b+=dp[0][i][0];
    for(int i=1;i<=p;i++) c+=dp[0][0][i];
    printf("%.9f %.9f %.9f\n",a,b,c);
    return 0;
}
时间: 2024-10-05 06:17:37

Codeforces Round #301 (Div. 2) D. Bad Luck Island 概率DP的相关文章

[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 #293 (Div. 2) D. Ilya and Escalator (概率DP)

dp[i][j]表示第i秒电梯进去的人数为j时的概率.由于概率比较好求,而且这里的样本是有限个.所以可以先求出概率,然后用公式转化成期望. #include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algorithm> #include <stdlib.h> #include <map> #include <

Codeforces Round #233 (Div. 2)D. Painting The Wall 概率DP

                                                                               D. Painting The Wall User ainta decided to paint a wall. The wall consists of n2 tiles, that are arranged in an n × n table. Some tiles are painted, and the others are not

Codeforces Round #597 (Div. 2) E. Hyakugoku and Ladders 概率dp

E. Hyakugoku and Ladders Hyakugoku has just retired from being the resident deity of the South Black Snail Temple in order to pursue her dream of becoming a cartoonist. She spent six months in that temple just playing "Cat's Cradle" so now she w

Codeforces Round #301 (Div. 2) -- (A,B,C,D)

题目传送:Codeforces Round #301 (Div. 2) A. Combination Lock 水题,求最小移动次数,简单贪心一下即可 AC代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cmath> #include <queue> #include <stack> #i

DFS/BFS Codeforces Round #301 (Div. 2) C. Ice Cave

题目传送门 1 /* 2 题意:告诉起点终点,踩一次, '.'变成'X',再踩一次,冰块破碎,问是否能使终点冰破碎 3 DFS:如题解所说,分三种情况:1. 如果两点重合,只要往外走一步再走回来就行了:2. 若两点相邻, 4 那么要不就是踩一脚就破了或者踩一脚走开再走回来踩一脚破了:3. 普通的搜索看是否能到达, 5 若能还是要讨论终点踩几脚的问题:) 6 DFS 耗时大,险些超时,可以用BFS来做 7 */ 8 #include <cstdio> 9 #include <algorit

贪心 Codeforces Round #301 (Div. 2) A. Combination Lock

题目传送门 1 /* 2 贪心水题:累加到目标数字的距离,两头找取最小值 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cstring> 8 using namespace std; 9 10 const int MAXN = 1e3 + 10; 11 const int INF = 0x3f3f3f3f; 12 char s[MAXN],

贪心 Codeforces Round #301 (Div. 2) B. School Marks

题目传送门 1 /* 2 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 3 num1是输出的1的个数,numy是除此之外的数都为y,此时的numy是最少需要的,这样才可能中位数大于等于y 4 */ 5 #include <cstdio> 6 #include <iostream> 7 #include <algorithm> 8 #include <cstring> 9 using na

CodeForces Round #301 Div.2

今天唯一的成果就是把上次几个人一起开房打的那场cf补一下. A. Combination Lock 此等水题看一眼样例加上那个配图我就明白题意了,可是手抽没有注释掉freopen,WA了一发. 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 const int maxn = 1000 + 10; 5 6 char s1[maxn], s2[maxn]; 7 8 int main() 9 { 10 int n; cin >>