CF540D Bad Luck Island(期望dp)

传送门

解题思路

  比较容易的一道期望\(dp\),设\(f[i][j][k]\)表示石头\(i\)个,剪刀\(j\)个,步子\(l\)个。然后转移的时候用组合数算一下就好了。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>

using namespace std;
const int MAXN = 105;

int r,s,p;
double f[MAXN][MAXN][MAXN],ans1,ans2,ans3;

inline int calc(int x,int y,int z){
    return max(((x+y+z)*(x+y+z-1)-x*(x-1)-y*(y-1)-z*(z-1))/2,1);
}

int main(){
    scanf("%d%d%d",&r,&s,&p);
    f[r][s][p]=1.0;
    for(int i=r;i>=0;i--)
        for(int j=s;j>=0;j--)
            for(int l=p;l>=0;l--){
                if(i==0 && j==0 && l==0) continue;
                if(i==r && j==s && l==p) continue;
                // cout<<i<<" "<<j<<" "<<l<<" "<<calc(i,j,l)<<endl;
                f[i][j][l]+=f[i+1][j][l]*((double)((i+1)*l)/calc(i+1,j,l));
                f[i][j][l]+=f[i][j+1][l]*((double)((j+1)*i)/calc(i,j+1,l));
                f[i][j][l]+=f[i][j][l+1]*((double)((l+1)*j)/calc(i,j,l+1));
            }
    for(int i=1;i<=r;i++) ans1+=f[i][0][0];
    for(int i=1;i<=s;i++) ans2+=f[0][i][0];
    for(int i=1;i<=p;i++) ans3+=f[0][0][i];
    printf("%.12lf %.12lf %.12lf",ans1,ans2,ans3);
    return 0;
}

原文地址:https://www.cnblogs.com/sdfzsyq/p/10050601.html

时间: 2024-11-13 09:16:06

CF540D Bad Luck Island(期望dp)的相关文章

cf540D. Bad Luck Island(概率dp)

题意 岛上有三个物种:剪刀$s$.石头$r$.布$p$ 其中剪刀能干掉布,布能干掉石头,石头能干掉剪刀 每天会从这三个物种中发生一场战争(也就是说其中的一个会被干掉) 问最后仅有$s/r/p$物种生存的概率 Sol 还是想复杂了啊,我列的状态时$f[i][j], g[i][j],t[i][j]$分别表示第$i$天,$j$个$s, r, p$活着的概率 然而转移了一下午也没转移出来.. 标算比我简单的多,直接设$f[i][j][k]$表示剩下$i$个$s$,$j$个$r$,$k$个$p$的概率 然

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

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

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

CF540D Bad Luck Island

嘟嘟嘟 看到数据范围很小,就可以暴力\(O(n ^ 3)\)dp啦. 我们令\(dp[i][j][k]\)表示这三种人分别剩\(i, j, k\)个的概率.然后枚举谁挂了就行. 这里的重点在于两个人相遇的概率是多少,拿\(i, j\)举例,乍一看是\(\frac{i * j}{(i + j + k) * (i + j + k - 1)}\),但这里包含了同一种族相遇的概率,这种情况还应该转移到\(dp[i][j][k]\),这样无限循环下去还是到了这个状态.所以我们的概率不应该包含同一种人相遇的

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的返回值均

[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 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, th