# 【bzoj4832】[Lydsy2017年4月月赛]抵制克苏恩 概率期望dp

1
1 1 1 1

0.25

#include <cstdio>
#include <cstring>
double p[55][8][8][8] , f[55][8][8][8];
int main()
{
int T;
scanf("%d" , &T);
while(T -- )
{
memset(p , 0 , sizeof(p)) , memset(f , 0 , sizeof(f));
int n , a , b , c , i , j , k , l;
double ans = 0;
scanf("%d%d%d%d" , &n , &a , &b , &c) , p[0][a][b][c] = 1;
for(i = 0 ; i < n ; i ++ )
{
for(j = 0 ; j <= 7 ; j ++ )
{
for(k = 0 ; k <= 7 ; k ++ )
{
for(l = 0 ; l <= 7 ; l ++ )
{
p[i + 1][j][k][l] += p[i][j][k][l] / (1 + j + k + l) , f[i + 1][j][k][l] += (f[i][j][k][l] + p[i][j][k][l]) / (1 + j + k + l);
if(j) p[i + 1][j - 1][k][l] += p[i][j][k][l] * j / (1 + j + k + l) , f[i + 1][j - 1][k][l] += f[i][j][k][l] * j / (1 + j + k + l);
if(k)
{
if(j + k + l == 7) p[i + 1][j + 1][k - 1][l] += p[i][j][k][l] * k / (1 + j + k + l) , f[i + 1][j + 1][k - 1][l] += f[i][j][k][l] * k / (1 + j + k + l);
else p[i + 1][j + 1][k - 1][l + 1] += p[i][j][k][l] * k / (1 + j + k + l) , f[i + 1][j + 1][k - 1][l + 1] += f[i][j][k][l] * k / (1 + j + k + l);
}
if(l)
{
if(j + k + l == 7) p[i + 1][j][k + 1][l - 1] += p[i][j][k][l] * l / (1 + j + k + l) , f[i + 1][j][k + 1][l - 1] += f[i][j][k][l] * l / (1 + j + k + l);
else p[i + 1][j][k + 1][l] += p[i][j][k][l] * l / (1 + j + k + l) , f[i + 1][j][k + 1][l] += f[i][j][k][l] * l / (1 + j + k + l);
}
}
}
}
}
for(i = 0 ; i <= 7 ; i ++ )
for(j = 0 ; j <= 7 ; j ++ )
for(k = 0 ; k <= 7 ; k ++ )
ans += f[n][i][j][k];
printf("%.2lf\n" , ans);
}
return 0;
}


posted @ 2017-10-28 14:27  GXZlegend  阅读(451)  评论(0编辑  收藏  举报