考试时又翻车了.....
一定要及时调整自己的思路!!!
随从最多有7个,只有三种,所以把每一种随从多开一维
so:f[i][j][k][l]为到第i次攻击前,场上有j个1血,k个2血,l个3血随从的概率
最后利用期望的可加性都加起来就好了
ps.30滴血受到四五十伤害,完全tm不符合逻辑啊,mdzz!!!
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int T,a,b,c,n;
double f[55][8][8][8],ans;
int main()
{
//freopen("defcthun.in","r",stdin);
//freopen("defcthun.out","w",stdout);
scanf("%d",&T);
for(int i=1;i<=T;i++)
{
scanf("%d%d%d%d",&n,&a,&b,&c);
ans=0; memset(f,0,sizeof f);
f[1][a][b][c]=1;
for(int i=1;i<=n;i++)
for(int j=0;j<=7;j++)
for(int k=0;k<=7;k++)
for(int l=0;l<=7;l++){
if(!f[i][j][k][l]) continue;
ans+=(double)f[i][j][k][l]*1.0/(1.0+j+k+l);
if(i==n) continue;
f[i+1][j][k][l]+=(double)f[i][j][k][l]*1.0/(1.0+j+k+l);
if(j>0) f[i+1][j-1][k][l]+=(double)f[i][j][k][l]*j/(1.0+j+k+l);
if(k>0){
if(j+k+l==7) f[i+1][j+1][k-1][l]+=(double)f[i][j][k][l]*k/(1.0+j+k+l);
else f[i+1][j+1][k-1][l+1]+=(double)f[i][j][k][l]*k/(1.0+j+k+l);
}
if(l>0){
if(j+k+l==7) f[i+1][j][k+1][l-1]+=(double)f[i][j][k][l]*l/(1.0+j+k+l);
else f[i+1][j][k+1][l]+=(double)f[i][j][k][l]*l/(1.0+j+k+l);
}
}
printf("%0.2lf\n",ans);
}
return 0;
}