题意:3个物种分别有r,s,p个第一种吃第二种,第二种吃第三种,第三种吃第一种,每隔一段时间两个生物相遇,问经过足够长的时间后每个物种存活(其他物种死亡)的概率。
dp[i][j][k]表示三个物种分别为i,j,k且第一个物种存活下的概率。状态转移为dp[i][j][k] = (i*j*dp[i][j-1][k]+i*k*dp[i-1][j][k]+j*k*dp[i][j][k-1])/(i*j+i*k+j*k).
#include<bits/stdc++.h>
using namespace std;
double dp[101][101][101];
double dfs(int i,int j,int k){
if(!k) return dp[i][j][k]=1;
if(!(i&&j)) return dp[i][j][k]=0;
if(dp[i][j][k]) return dp[i][j][k];
return dp[i][j][k]=(i*j*dfs(i,j-1,k)+k*i*dfs(i-1,j,k)+j*k*dfs(i,j,k-1))/(i*j+j*k+k*i);
}
int main()
{
int r,s,p;
cin>>r>>s>>p;
printf("%.12f ",dfs(r,s,p));
memset(dp,0,sizeof dp);
printf("%.12f ",dfs(s,p,r));
memset(dp,0,sizeof dp);
printf("%.12f\n",dfs(p,r,s));
}