题意:
解法:
d[i][j][k]表示状态(i,j,k)到达终止状态的期望次数.
可以由d[i+1][j][k],d[i][j+1][k],d[i][j][k+1]转移而来.
记忆化搜索一下即可.
code:
#include<bits/stdc++.h>
using namespace std;
#define int long long
double d[105][105][105];
int a,b,c;
double dfs(int i,int j,int k){
if(d[i][j][k]>=0)return d[i][j][k];
if(i==100||j==100||k==100)return d[i][j][k]=0;
double ans=0;
ans+=1.0*i/(i+j+k)*(1+dfs(i+1,j,k));
ans+=1.0*j/(i+j+k)*(1+dfs(i,j+1,k));
ans+=1.0*k/(i+j+k)*(1+dfs(i,j,k+1));
return d[i][j][k]=ans;
}
signed main(){
for(int i=0;i<=100;i++){
for(int j=0;j<=100;j++){
for(int k=0;k<=100;k++){
d[i][j][k]=-1;
}
}
}
cin>>a>>b>>c;
double ans=dfs(a,b,c);
printf("%.6f\n",ans);
return 0;
}