BZOJ4832 抵制克苏恩(概率期望+动态规划)

  注意到A+B+C很小,容易想到设f[i][A][B][C]为第i次攻击后有A个血量为1、B个血量为2、C个血量为3的期望伤害,倒推暴力转移即可。

#include<iostream> 
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
    int x=0,f=1;char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x*f;
}
double f[59][8][8][8];
int T,n,a,b,c;
int main()
{
#ifndef ONLINE_JUDGE
    freopen("bzoj4832.in","r",stdin);
    freopen("bzoj4832.out","w",stdout);
    const char LL[]="%I64d\n";
#else
    const char LL[]="%lld\n";
#endif
    T=read();
    for (int i=1;i<=50;i++)
        for (int x=0;x<=7;x++)
            for (int y=0;y<=7-x;y++)
                for (int z=0;z<=7-x-y;z++)
                {
                    f[i][x][y][z]=f[i-1][x][y][z]+1;
                    if (x) f[i][x][y][z]+=f[i-1][x-1][y][z]*x;
                    if (y) f[i][x][y][z]+=f[i-1][x+1][y-1][z+(x+y+z<7)]*y;
                    if (z) f[i][x][y][z]+=f[i-1][x][y+1][z-1+(x+y+z<7)]*z;
                    f[i][x][y][z]/=(x+y+z+1);
                }
    while (T--)
    {
        n=read(),a=read(),b=read(),c=read();
        printf("%.2lf\n",f[n][a][b][c]);
    }
    return 0;
}

 

posted @ 2018-11-23 23:10  Gloid  阅读(220)  评论(0编辑  收藏  举报