[CSP-S模拟测试]:山屋惊魂(模拟)

题目传送门(内部题90)


输入格式

  前四行依次表示每种属性:$Might$、$Speed$、$Sanity$、$Knowledge$。每行一个$8$位数表示该属性的$8$个档的值,第二个数表示初始在哪一档。
  第五行一个正整数$N$,表示事件数。
  接下来$N$行,每行表示一个事件,分为$2$大类,举例如下:
  $1$)
  直接生效的事件:
  $Speed\ +1$或$Speed\ -1$表示$Speed$属性值增加/减少一档。
  $Speed\ +2?$或$Speed\ -2?$表示$Speed$属性值增加/减少$2$个骰子的“判定”。
  $2$)
  通过“判定”决定是否生效的事件:
  $Speed<10\ Might\ +1$表示$Speed$的“判定”小于$10$的话,$Might$加$1$。
  $Speed>10\ Might\ +1?$表示$Speed$的“判定”大于$10$的话,$Might$增加$1$个骰子的“判定”。
  同样的,也有$>=$和$<=$的“判定”条件。


输出格式

  第一行一个数表示探险者中途退出探险的概率,百分比制,保留$2$位小数。
  接下来四行,每行$8$个数,表示最终探险者该属性值为$1\sim 8$的概率,百分比制,保留$2$位小数。注:如探险者任何时刻退出探险,游戏结束,所有属性值都视为$0$。


样例

样例输入1:

23345568 3
33346677 4
14445567 4
34456778 3
4
Might +1
Speed +1
Sanity -3
Knowledge +8

样例输出1:

0.00
0.00 0.00 0.00 100.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 100.00 0.00 0.00
100.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00

样例输入2:

23345568 3
33346677 4
14445567 4
34456778 3
4
Might +1?
Speed -1?
Sanity -3
Sanity < 2 Knowledge -3

样例输出2:

66.67
0.00 0.00 11.11 11.11 11.11 0.00 0.00 0.00
0.00 0.00 22.22 11.11 0.00 0.00 0.00 0.00
33.33 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 33.33 0.00 0.00 0.00 0.00


数据范围与提示

对于$30\%$的数据,只有直接生效的事件,不存在“判定”,玩家没有退出探险。
对于$60\%$的数据,只有直接生效的事件。
对于$100\%$的数据,$N\leqslant 100$。
数据保证属性值条是单调不降的,初始值是合法的($1\sim 8$)。


题解

又是一道假期望,然而却是一道模拟……

开一个数组记录一下当前情况下所有的概率即可。

死亡概率就是$1-$其中一行的概率和。

但是我真心希望你不要把它打成这样$\downarrow$

而应该把它打成这样$\downarrow$

时间复杂度:$\Theta(65536\times n)$(根据打法不同各有不同,这个时间复杂度是我的打法的时间复杂度)。

期望得分:$100$分。

实际得分:$100$分。


代码时刻

我的极丑的代码:

#include<bits/stdc++.h>
using namespace std;
char ch[9];
int n,Map[5][9];
double dp[9][17],f[2][9][9][9][9],sum,ans[5][9];
bool now;
void pre_work()
{
	dp[0][0]=1.0;
	for(int i=0;i<8;i++)
		for(int j=0;j<15;j++)
		{
			dp[i+1][j]+=dp[i][j];
			dp[i+1][j+1]+=dp[i][j];
			dp[i+1][j+2]+=dp[i][j];
		}
	for(int i=1;i<=8;i++)
		for(int j=0;j<17;j++)
			for(int k=0;k<i;k++)
				dp[i][j]/=3.0;
}
void work1(int id,int opt)
{
	now^=1;memset(f[now],0,sizeof(f[now]));
	char c;
	while(c<='0'||c>'9')c=getchar();
	int val=c-'0';
	c=getchar();bool fl=0;
	if(c=='?')fl=1;
	else val*=opt;
	for(int i=1;i<=8;i++)
		for(int j=1;j<=8;j++)
			for(int k=1;k<=8;k++)
				for(int l=1;l<=8;l++)
				{
					if(fl)
					{
						for(int g=0;g<=16;g++)
						{
							if(id==1&&i+g*opt>0)f[now][min(i+g*opt,8)][j][k][l]+=f[!now][i][j][k][l]*dp[val][g];
							if(id==2&&j+g*opt>0)f[now][i][min(j+g*opt,8)][k][l]+=f[!now][i][j][k][l]*dp[val][g];
							if(id==3&&k+g*opt>0)f[now][i][j][min(k+g*opt,8)][l]+=f[!now][i][j][k][l]*dp[val][g];
							if(id==4&&l+g*opt>0)f[now][i][j][k][min(l+g*opt,8)]+=f[!now][i][j][k][l]*dp[val][g];
						}
					}
					else
					{
						if(id==1&&i+val>0)f[now][min(i+val,8)][j][k][l]+=f[!now][i][j][k][l];
						if(id==2&&j+val>0)f[now][i][min(j+val,8)][k][l]+=f[!now][i][j][k][l];
						if(id==3&&k+val>0)f[now][i][j][min(k+val,8)][l]+=f[!now][i][j][k][l];
						if(id==4&&l+val>0)f[now][i][j][k][min(l+val,8)]+=f[!now][i][j][k][l];
					}
				}
}
void work2(int id,int opt)
{
	now^=1;memset(f[now],0,sizeof(f[now]));
	int ju,son,num;bool fl=0;
	scanf("%d%s",&ju,ch+1);
	switch(ch[2])
	{
		case 'i':son=1;break;
		case 'p':son=2;break;
		case 'a':son=3;break;
		case 'n':son=4;break;
	}
	char c=getchar();
	while(c!='+'&&c!='-'&&c!='<'&&c!='>')c=getchar();
	int opp=(c=='+')?1:-1;
	while(c<='0'||c>'9')c=getchar();
	int val=c-'0';
	c=getchar();
	if(c=='?')fl=1;
	else val*=opp;
	for(int i=1;i<=8;i++)
		for(int j=1;j<=8;j++)
			for(int k=1;k<=8;k++)
				for(int l=1;l<=8;l++)
				{
					switch(id)
					{
						case 1:num=Map[1][i];break;
						case 2:num=Map[2][j];break;
						case 3:num=Map[3][k];break;
						case 4:num=Map[4][l];break;
					}
					for(int pd=0;pd<=16;pd++)
					{
						bool hsw;
						switch(opt)
						{
							case 3:hsw=(pd>ju);break;
							case 4:hsw=(pd<ju);break;
							case 5:hsw=(pd>=ju);break;
							case 6:hsw=(pd<=ju);break;
						}
						if(hsw)
						{
							if(fl)
							{
								for(int g=0;g<=16;g++)
								{
									if(son==1&&i+g*opp>0)f[now][min(i+g*opp,8)][j][k][l]+=f[!now][i][j][k][l]*dp[val][g]*dp[num][pd];
									if(son==2&&j+g*opp>0)f[now][i][min(j+g*opp,8)][k][l]+=f[!now][i][j][k][l]*dp[val][g]*dp[num][pd];
									if(son==3&&k+g*opp>0)f[now][i][j][min(k+g*opp,8)][l]+=f[!now][i][j][k][l]*dp[val][g]*dp[num][pd];
									if(son==4&&l+g*opp>0)f[now][i][j][k][min(l+g*opp,8)]+=f[!now][i][j][k][l]*dp[val][g]*dp[num][pd];
								}
							}
							else
							{
								if(son==1&&i+val>0)f[now][min(i+val,8)][j][k][l]+=f[!now][i][j][k][l]*dp[num][pd];
								if(son==2&&j+val>0)f[now][i][min(j+val,8)][k][l]+=f[!now][i][j][k][l]*dp[num][pd];
								if(son==3&&k+val>0)f[now][i][j][min(k+val,8)][l]+=f[!now][i][j][k][l]*dp[num][pd];
								if(son==4&&l+val>0)f[now][i][j][k][min(l+val,8)]+=f[!now][i][j][k][l]*dp[num][pd];
							}
						}
						else f[now][i][j][k][l]+=f[!now][i][j][k][l]*dp[num][pd];
					}
				}
}
void read()
{
	for(int i=1;i<=4;i++)
	{
		scanf("%s",ch+1);
		for(int j=1;j<=8;j++)Map[i][j]=ch[j]-'0';
		scanf("%d",&Map[i][0]);
	}
	f[0][Map[1][0]][Map[2][0]][Map[3][0]][Map[4][0]]=1.0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",ch+1);
		int id;switch(ch[2])
		{
			case 'i':id=1;break;
			case 'p':id=2;break;
			case 'a':id=3;break;
			case 'n':id=4;break;
		}
		char c=getchar();
		while(c!='+'&&c!='-'&&c!='<'&&c!='>')c=getchar();
		if(c=='+')work1(id,1);
		if(c=='-')work1(id,-1);
		if(c=='>'){c=getchar();if(c==' ')work2(id,3);else work2(id,5);}
		if(c=='<'){c=getchar();if(c==' ')work2(id,4);else work2(id,6);}
	}
}
int main()
{
	pre_work();
	read();
	for(int i=1;i<=8;i++)
		for(int j=1;j<=8;j++)
			for(int k=1;k<=8;k++)
				for(int l=1;l<=8;l++)
				{
					sum+=f[now][i][j][k][l];
					ans[1][Map[1][i]]+=f[now][i][j][k][l];
					ans[2][Map[2][j]]+=f[now][i][j][k][l];
					ans[3][Map[3][k]]+=f[now][i][j][k][l];
					ans[4][Map[4][l]]+=f[now][i][j][k][l];
				}
	printf("%.2lf\n",(1-sum)*100);
	for(int i=1;i<=4;i++,puts(""))
		for(int j=1;j<=8;j++)printf("%.2lf ",ans[i][j]*100);
	return 0;
}

Rorschach_XR的代码(仅供欣赏,请勿消费):

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int lev[6][11],ini[6],n;
double res[15][105];
struct thing
{
    int sk;
    int op;
    int num;
    int consk,conp,conum;
}t[105];
double ans[6][11],dead;
int abss(int x)
{
    return x>0?x:-x;
}
void pre()
{
    res[1][0]=0.333333333333333;
    res[1][1]=0.333333333333333;
    res[1][2]=0.333333333333333;
    res[2][0]=0.111111111111111;
    res[2][1]=0.222222222222222;
    res[2][2]=0.333333333333333;
    res[2][3]=0.222222222222222;
    res[2][4]=0.111111111111111;
    res[3][0]=0.037037037037037;
    res[3][1]=0.111111111111111;
    res[3][2]=0.222222222222222;
    res[3][3]=0.259259259259259;
    res[3][4]=0.222222222222222;
    res[3][5]=0.111111111111111;
    res[3][6]=0.037037037037037;
    res[4][0]=0.012345679012346;
    res[4][1]=0.049382716049383;
    res[4][2]=0.123456790123457;
    res[4][3]=0.197530864197531;
    res[4][4]=0.234567901234568;
    res[4][5]=0.197530864197531;
    res[4][6]=0.123456790123457;
    res[4][7]=0.049382716049383;
    res[4][8]=0.012345679012346;
    res[5][0]=0.004115226337449;
    res[5][1]=0.020576131687243;
    res[5][2]=0.061728395061728;
    res[5][3]=0.123456790123457;
    res[5][4]=0.185185185185185;
    res[5][5]=0.209876543209877;
    res[5][6]=0.185185185185185;
    res[5][7]=0.123456790123457;
    res[5][8]=0.061728395061728;
    res[5][9]=0.020576131687243;
    res[5][10]=0.004115226337449;
    res[6][0]=0.001371742112483;
    res[6][1]=0.008230452674897;
    res[6][2]=0.028806584362140;
    res[6][3]=0.068587105624143;
    res[6][4]=0.123456790123457;
    res[6][5]=0.172839506172840;
    res[6][6]=0.193415637860083;
    res[6][7]=0.172839506172840;
    res[6][8]=0.123456790123457;
    res[6][9]=0.068587105624143;
    res[6][10]=0.028806584362140;
    res[6][11]=0.008230452674897;
    res[6][12]=0.001371742112483;
    res[7][0]=0.000457247370828;
    res[7][1]=0.003200731595793;
    res[7][2]=0.012802926383173;
    res[7][3]=0.035208047553727;
    res[7][4]=0.073616826703246;
    res[7][5]=0.121627800640146;
    res[7][6]=0.163237311385458;
    res[7][7]=0.179698216735253;
    res[7][8]=0.163237311385458;
    res[7][9]=0.121627800640146;
    res[7][10]=0.073616826703246;
    res[7][11]=0.035208047553727;
    res[7][12]=0.012802926383173;
    res[7][13]=0.003200731595793;
    res[7][14]=0.000457247370828;
    res[8][0]=0.000152415790276;
    res[8][1]=0.001219326322207;
    res[8][2]=0.005486968449931;
    res[8][3]=0.017070568510898;
    res[8][4]=0.040542600213382;
    res[8][5]=0.076817558299041;
    res[8][6]=0.119493979576286;
    res[8][7]=0.154854442920286;
    res[8][8]=0.168724279835390;
    res[8][9]=0.154854442920286;
    res[8][10]=0.119493979576286;
    res[8][11]=0.076817558299041;
    res[8][12]=0.040542600213382;
    res[8][13]=0.017070568510898;
    res[8][14]=0.005486968449931;
    res[8][15]=0.001219326322207;
    res[8][16]=0.000152415790276;
}
int judge(char c1,char c2)
{
    if(c1=='M')return 1;
    else if(c1=='S'&&c2=='p')return 2;
    else if(c1=='S'&&c2=='a')return 3;
    else if(c1=='K')return 4;
    return -1;
}
int isop(char s)
{
    if(s=='+')return 1;
    else if(s=='-')return -1;
    return 0;
}
double dp[103][12][12][12][12];
#define Poss dp[x][n1][n2][n3][n4]
void work(int x,int n1,int n2,int n3,int n4)
{
    if(t[x].op==1)
    {
        if(t[x].sk==1)
        {
            int nxt=min(n1+t[x].num,8);
            if(nxt<=0)dead+=Poss;
            else dp[x+1][nxt][n2][n3][n4]+=Poss;
        }
        else if(t[x].sk==2)
        {
            int nxt=min(n2+t[x].num,8);
            if(nxt<=0)dead+=Poss;
            else dp[x+1][n1][nxt][n3][n4]+=Poss;
        }
        else if(t[x].sk==3)
        {
            int nxt=min(n3+t[x].num,8);
            if(nxt<=0)dead+=Poss;
            else dp[x+1][n1][n2][nxt][n4]+=Poss;
        }
        else if(t[x].sk==4)
        {
            int nxt=min(n4+t[x].num,8);
            if(nxt<=0)dead+=Poss;
            else dp[x+1][n1][n2][n3][nxt]+=Poss;
        }
    }
    else if(t[x].op==2)
    {
        if(t[x].sk==1)
        {
            for(int i=0;i<=abss(t[x].num)*2;i++)
            {
                int f=t[x].num>0?1:-1;
                int nxt=min(n1+f*i,8);
                if(nxt<=0)dead+=Poss*res[abss(t[x].num)][i];
                else dp[x+1][nxt][n2][n3][n4]+=Poss*res[abss(t[x].num)][i];
            }
        }
        else if(t[x].sk==2)
        {
            for(int i=0;i<=abss(t[x].num)*2;i++)
            {
                int f=t[x].num>0?1:-1;
                int nxt=min(n2+f*i,8);
                if(nxt<=0)dead+=Poss*res[abss(t[x].num)][i];
                else dp[x+1][n1][nxt][n3][n4]+=Poss*res[abss(t[x].num)][i];
            }
        }
        else if(t[x].sk==3)
        {
            for(int i=0;i<=abss(t[x].num)*2;i++)
            {
                int f=t[x].num>0?1:-1;
                int nxt=min(n3+f*i,8);
                if(nxt<=0)dead+=Poss*res[abss(t[x].num)][i];
                else dp[x+1][n1][n2][nxt][n4]+=Poss*res[abss(t[x].num)][i];
            }
        }
        else if(t[x].sk==4)
        {
            for(int i=0;i<=abss(t[x].num)*2;i++)
            {
                int f=t[x].num>0?1:-1;
                int nxt=min(n4+f*i,8);
                if(nxt<=0)dead+=Poss*res[abss(t[x].num)][i];
                else dp[x+1][n1][n2][n3][nxt]+=Poss*res[abss(t[x].num)][i];
            }
        }
    }
    else if(t[x].op==3)
    {
        if(t[x].sk==1)
        {
            if(t[x].conp==1)
            {
                if(t[x].consk==1)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[1][n1];i++)
                        ok+=res[lev[1][n1]][i];
                    int nxt=min(8,n1+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][nxt][n2][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==2)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[2][n2];i++)
                        ok+=res[lev[2][n2]][i];
                    int nxt=min(8,n1+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][nxt][n2][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==3)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[3][n3];i++)
                        ok+=res[lev[3][n3]][i];
                    int nxt=min(8,n1+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][nxt][n2][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==4)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[4][n4];i++)
                        ok+=res[lev[4][n4]][i];
                    int nxt=min(8,n1+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][nxt][n2][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
            else if(t[x].conp==2)
            {
                if(t[x].consk==1)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[1][n1];i++)
                        ok+=res[lev[1][n1]][i];
                    int nxt=min(8,n1+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][nxt][n2][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==2)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[2][n2];i++)
                        ok+=res[lev[2][n2]][i];
                    int nxt=min(8,n1+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][nxt][n2][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==3)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[3][n3];i++)
                        ok+=res[lev[3][n3]][i];
                    int nxt=min(8,n1+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][nxt][n2][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==4)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[4][n4];i++)
                        ok+=res[lev[4][n4]][i];
                    int nxt=min(8,n1+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][nxt][n2][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
            else if(t[x].conp==3)
            {
                if(t[x].consk==1)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[1][n1]][i];
                    int nxt=min(8,n1+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][nxt][n2][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==2)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[2][n2]][i];
                    int nxt=min(8,n1+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][nxt][n2][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==3)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[3][n3]][i];
                    int nxt=min(8,n1+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][nxt][n2][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==4)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[4][n4]][i];
                    int nxt=min(8,n1+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][nxt][n2][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
            else if(t[x].conp==4)
            {
                if(t[x].consk==1)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[1][n1]][i];
                    int nxt=min(8,n1+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][nxt][n2][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==2)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[2][n2]][i];
                    int nxt=min(8,n1+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][nxt][n2][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==3)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[3][n3]][i];
                    int nxt=min(8,n1+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][nxt][n2][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==4)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[4][n4]][i];
                    int nxt=min(8,n1+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][nxt][n2][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
        }
        else if(t[x].sk==2)
        {
            if(t[x].conp==1)
            {
                if(t[x].consk==1)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[1][n1];i++)
                        ok+=res[lev[1][n1]][i];
                    int nxt=min(8,n2+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][nxt][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==2)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[2][n2];i++)
                        ok+=res[lev[2][n2]][i];
                    int nxt=min(8,n2+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][nxt][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==3)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[3][n3];i++)
                        ok+=res[lev[3][n3]][i];
                    int nxt=min(8,n2+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][nxt][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==4)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[4][n4];i++)
                        ok+=res[lev[4][n4]][i];
                    int nxt=min(8,n2+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][nxt][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
            else if(t[x].conp==2)
            {
                if(t[x].consk==1)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[1][n1];i++)
                        ok+=res[lev[1][n1]][i];
                    int nxt=min(8,n2+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][nxt][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==2)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[2][n2];i++)
                        ok+=res[lev[2][n2]][i];
                    int nxt=min(8,n2+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][nxt][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==3)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[3][n3];i++)
                        ok+=res[lev[3][n3]][i];
                    int nxt=min(8,n2+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][nxt][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==4)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[4][n4];i++)
                        ok+=res[lev[4][n4]][i];
                    int nxt=min(8,n2+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][nxt][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
            else if(t[x].conp==3)
            {
                if(t[x].consk==1)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[1][n1]][i];
                    int nxt=min(8,n2+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][nxt][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==2)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[2][n2]][i];
                    int nxt=min(8,n2+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][nxt][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==3)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[3][n3]][i];
                    int nxt=min(8,n2+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][nxt][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==4)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[4][n4]][i];
                    int nxt=min(8,n2+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][nxt][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
            else if(t[x].conp==4)
            {
                if(t[x].consk==1)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[1][n1]][i];
                    int nxt=min(8,n2+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][nxt][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==2)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[2][n2]][i];
                    int nxt=min(8,n2+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][nxt][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==3)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[3][n3]][i];
                    int nxt=min(8,n2+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][nxt][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==4)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[4][n4]][i];
                    int nxt=min(8,n2+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][nxt][n3][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
        }
        else if(t[x].sk==3)
        {
            if(t[x].conp==1)
            {
                if(t[x].consk==1)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[1][n1];i++)
                        ok+=res[lev[1][n1]][i];
                    int nxt=min(8,n3+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][nxt][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==2)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[2][n2];i++)
                        ok+=res[lev[2][n2]][i];
                    int nxt=min(8,n3+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][nxt][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==3)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[3][n3];i++)
                        ok+=res[lev[3][n3]][i];
                    int nxt=min(8,n3+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][nxt][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==4)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[4][n4];i++)
                        ok+=res[lev[4][n4]][i];
                    int nxt=min(8,n3+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][nxt][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
            else if(t[x].conp==2)
            {
                if(t[x].consk==1)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[1][n1];i++)
                        ok+=res[lev[1][n1]][i];
                    int nxt=min(8,n3+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][nxt][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==2)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[2][n2];i++)
                        ok+=res[lev[2][n2]][i];
                    int nxt=min(8,n3+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][nxt][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==3)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[3][n3];i++)
                        ok+=res[lev[3][n3]][i];
                    int nxt=min(8,n3+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][nxt][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==4)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[4][n4];i++)
                        ok+=res[lev[4][n4]][i];
                    int nxt=min(8,n3+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][nxt][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
            else if(t[x].conp==3)
            {
                if(t[x].consk==1)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[1][n1]][i];
                    int nxt=min(8,n3+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][nxt][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==2)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[2][n2]][i];
                    int nxt=min(8,n3+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][nxt][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==3)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[3][n3]][i];
                    int nxt=min(8,n3+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][nxt][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==4)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[4][n4]][i];
                    int nxt=min(8,n3+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][nxt][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
            else if(t[x].conp==4)
            {
                if(t[x].consk==1)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[1][n1]][i];
                    int nxt=min(8,n3+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][nxt][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==2)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[2][n2]][i];
                    int nxt=min(8,n3+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][nxt][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==3)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[3][n3]][i];
                    int nxt=min(8,n3+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][nxt][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==4)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[4][n4]][i];
                    int nxt=min(8,n3+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][nxt][n4]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
        }
        else if(t[x].sk==4)
        {
            if(t[x].conp==1)
            {
                if(t[x].consk==1)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[1][n1];i++)
                        ok+=res[lev[1][n1]][i];
                    int nxt=min(8,n4+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][n3][nxt]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==2)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[2][n2];i++)
                        ok+=res[lev[2][n2]][i];
                    int nxt=min(8,n4+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][n3][nxt]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==3)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[3][n3];i++)
                        ok+=res[lev[3][n3]][i];
                    int nxt=min(8,n4+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][n3][nxt]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==4)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[4][n4];i++)
                        ok+=res[lev[4][n4]][i];
                    int nxt=min(8,n4+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][n3][nxt]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
            else if(t[x].conp==2)
            {
                if(t[x].consk==1)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[1][n1];i++)
                        ok+=res[lev[1][n1]][i];
                    int nxt=min(8,n4+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][n3][nxt]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==2)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[2][n2];i++)
                        ok+=res[lev[2][n2]][i];
                    int nxt=min(8,n4+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][n3][nxt]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==3)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[3][n3];i++)
                        ok+=res[lev[3][n3]][i];
                    int nxt=min(8,n4+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][n3][nxt]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==4)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[4][n4];i++)
                        ok+=res[lev[4][n4]][i];
                    int nxt=min(8,n4+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][n3][nxt]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
            else if(t[x].conp==3)
            {
                if(t[x].consk==1)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[1][n1]][i];
                    int nxt=min(8,n4+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][n3][nxt]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==2)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[2][n2]][i];
                    int nxt=min(8,n4+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][n3][nxt]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==3)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[3][n3]][i];
                    int nxt=min(8,n4+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][n3][nxt]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==4)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[4][n4]][i];
                    int nxt=min(8,n4+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][n3][nxt]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
            else if(t[x].conp==4)
            {
                if(t[x].consk==1)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[1][n1]][i];
                    int nxt=min(8,n4+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][n3][nxt]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==2)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[2][n2]][i];
                    int nxt=min(8,n4+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][n3][nxt]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==3)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[3][n3]][i];
                    int nxt=min(8,n4+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][n3][nxt]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].consk==4)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[4][n4]][i];
                    int nxt=min(8,n4+t[x].num);
                    if(nxt<=0)dead+=Poss*ok;
                    else dp[x+1][n1][n2][n3][nxt]+=Poss*ok;
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
        }
    }
    else if(t[x].op==4)
    {
        if(t[x].sk==1)
        {
            if(t[x].consk==1)
            {
                if(t[x].conp==1)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[1][n1];i++)
                        ok+=res[lev[1][n1]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n1+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][nxt][n2][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==2)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[1][n1];i++)
                        ok+=res[lev[1][n1]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n1+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][nxt][n2][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==3)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[1][n1]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n1+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][nxt][n2][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==4)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[1][n1]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n1+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][nxt][n2][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
            else if(t[x].consk==2)
            {
                if(t[x].conp==1)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[2][n2];i++)
                        ok+=res[lev[2][n2]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n1+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][nxt][n2][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==2)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[2][n2];i++)
                        ok+=res[lev[2][n2]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n1+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][nxt][n2][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==3)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[2][n2]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n1+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][nxt][n2][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==4)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[2][n2]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n1+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][nxt][n2][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
            else if(t[x].consk==3)
            {
                if(t[x].conp==1)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[3][n3];i++)
                        ok+=res[lev[3][n3]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n1+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][nxt][n2][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==2)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[3][n3];i++)
                        ok+=res[lev[3][n3]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n1+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][nxt][n2][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==3)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[3][n3]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n1+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][nxt][n2][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==4)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[3][n3]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n1+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][nxt][n2][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
            else if(t[x].consk==4)
            {
                if(t[x].conp==1)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[4][n4];i++)
                        ok+=res[lev[4][n4]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n1+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][nxt][n2][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==2)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[4][n4];i++)
                        ok+=res[lev[4][n4]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n1+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][nxt][n2][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==3)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[4][n4]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n1+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][nxt][n2][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==4)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[4][n4]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n1+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][nxt][n2][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
        }
        else if(t[x].sk==2)
        {
            if(t[x].consk==1)
            {
                if(t[x].conp==1)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[1][n1];i++)
                        ok+=res[lev[1][n1]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n2+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][nxt][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==2)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[1][n1];i++)
                        ok+=res[lev[1][n1]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n2+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][nxt][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==3)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[1][n1]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n2+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][nxt][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==4)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[1][n1]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n2+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][nxt][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
            else if(t[x].consk==2)
            {
                if(t[x].conp==1)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[2][n2];i++)
                        ok+=res[lev[2][n2]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n2+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][nxt][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==2)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[2][n2];i++)
                        ok+=res[lev[2][n2]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n2+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][nxt][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==3)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[2][n2]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n2+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][nxt][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==4)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[2][n2]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n2+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][nxt][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
            else if(t[x].consk==3)
            {
                if(t[x].conp==1)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[3][n3];i++)
                        ok+=res[lev[3][n3]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n2+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][nxt][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==2)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[3][n3];i++)
                        ok+=res[lev[3][n3]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n2+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][nxt][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==3)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[3][n3]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n2+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][nxt][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==4)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[3][n3]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n2+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][nxt][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
            else if(t[x].consk==4)
            {
                if(t[x].conp==1)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[4][n4];i++)
                        ok+=res[lev[4][n4]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n2+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][nxt][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==2)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[4][n4];i++)
                        ok+=res[lev[4][n4]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n2+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][nxt][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==3)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[4][n4]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n2+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][nxt][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==4)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[4][n4]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n2+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][nxt][n3][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
        }
        else if(t[x].sk==3)
        {
            if(t[x].consk==1)
            {
                if(t[x].conp==1)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[1][n1];i++)
                        ok+=res[lev[1][n1]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n3+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][nxt][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==2)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[1][n1];i++)
                        ok+=res[lev[1][n1]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n3+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][nxt][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==3)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[1][n1]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n3+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][nxt][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==4)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[1][n1]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n3+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][nxt][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
            else if(t[x].consk==2)
            {
                if(t[x].conp==1)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[2][n2];i++)
                        ok+=res[lev[2][n2]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n3+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][nxt][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==2)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[2][n2];i++)
                        ok+=res[lev[2][n2]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n3+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][nxt][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==3)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[2][n2]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n3+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][nxt][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==4)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[2][n2]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n3+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][nxt][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
            else if(t[x].consk==3)
            {
                if(t[x].conp==1)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[3][n3];i++)
                        ok+=res[lev[3][n3]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n3+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][nxt][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==2)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[3][n3];i++)
                        ok+=res[lev[3][n3]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n3+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][nxt][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==3)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[3][n3]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n3+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][nxt][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==4)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[3][n3]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n3+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][nxt][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
            else if(t[x].consk==4)
            {
                if(t[x].conp==1)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[4][n4];i++)
                        ok+=res[lev[4][n4]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n3+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][nxt][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==2)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[4][n4];i++)
                        ok+=res[lev[4][n4]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n3+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][nxt][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==3)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[4][n4]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n3+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][nxt][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==4)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[4][n4]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n3+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][nxt][n4]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
        }
        else if(t[x].sk==4)
        {
            if(t[x].consk==1)
            {
                if(t[x].conp==1)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[1][n1];i++)
                        ok+=res[lev[1][n1]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n4+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][n3][nxt]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==2)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[1][n1];i++)
                        ok+=res[lev[1][n1]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n4+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][n3][nxt]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==3)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[1][n1]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n4+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][n3][nxt]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==4)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[1][n1]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n4+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][n3][nxt]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
            else if(t[x].consk==2)
            {
                if(t[x].conp==1)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[2][n2];i++)
                        ok+=res[lev[2][n2]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n4+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][n3][nxt]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==2)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[2][n2];i++)
                        ok+=res[lev[2][n2]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n4+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][n3][nxt]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==3)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[2][n2]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n4+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][n3][nxt]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==4)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[2][n2]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n4+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][n3][nxt]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
            else if(t[x].consk==3)
            {
                if(t[x].conp==1)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[3][n3];i++)
                        ok+=res[lev[3][n3]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n4+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][n3][nxt]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==2)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[3][n3];i++)
                        ok+=res[lev[3][n3]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n4+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][n3][nxt]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==3)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[3][n3]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n4+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][n3][nxt]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==4)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[3][n3]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n4+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][n3][nxt]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
            else if(t[x].consk==4)
            {
                if(t[x].conp==1)
                {
                    double ok=0;
                    for(int i=t[x].conum+1;i<=2*lev[4][n4];i++)
                        ok+=res[lev[4][n4]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n4+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][n3][nxt]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==2)
                {
                    double ok=0;
                    for(int i=t[x].conum;i<=2*lev[4][n4];i++)
                        ok+=res[lev[4][n4]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n4+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][n3][nxt]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==3)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum-1;i++)
                        ok+=res[lev[4][n4]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n4+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][n3][nxt]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
                else if(t[x].conp==4)
                {
                    double ok=0;
                    for(int i=0;i<=t[x].conum;i++)
                        ok+=res[lev[4][n4]][i];
                    for(int i=0;i<=abss(t[x].num)*2;i++)
                    {
                        int f=t[x].num>0?1:-1;
                        int nxt=min(n4+f*i,8);
                        if(nxt<=0)dead+=Poss*ok*res[abss(t[x].num)][i];
                        else dp[x+1][n1][n2][n3][nxt]+=Poss*ok*res[abss(t[x].num)][i];
                    }
                    dp[x+1][n1][n2][n3][n4]+=Poss*(1.0-ok);
                }
            }
        }
    }
}

int main()
{
    char str[105];pre();
    for(int i=1;i<=4;i++)
    {
        scanf("%s",str+1);
        int len=strlen(str+1);
        for(int j=1;j<=len;j++)
            lev[i][j]=str[j]-'0';
        scanf("%d",&ini[i]);
    }
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%s",str+1);
        t[i].sk=judge(str[1],str[2]);
        scanf("%s",str+1);
        if(isop(str[1]))
        {
            int len=strlen(str+1);
            if(str[len]!='?')t[i].op=1;
            else t[i].op=2;
            int x=0,j=2;
            while(isdigit(str[j]))x=x*10+str[j]-'0',j++;
            t[i].num=isop(str[1])*x;
        }
        else
        {
            int len=strlen(str+1);
            if(len==1)
            {
                if(str[1]=='>')t[i].conp=1;
                else if(str[1]=='<')t[i].conp=3;
            }
            else
            {
                if(str[1]=='>')t[i].conp=2;
                else if(str[1]=='<')t[i].conp=4;
            }
            scanf("%s",str+1);
            int x=0,j=1;
            while(isdigit(str[j]))x=x*10+str[j]-'0',j++;
            t[i].conum=x;
            scanf("%s",str+1);
            t[i].consk=judge(str[1],str[2]);swap(t[i].consk,t[i].sk);
            scanf("%s",str+1);
            len=strlen(str+1);
            if(str[len]=='?')t[i].op=4;
            else t[i].op=3;
            x=0,j=2;
            while(isdigit(str[j]))x=x*10+str[j]-'0',j++;
            t[i].num=isop(str[1])*x;
        }
    }
    dp[1][ini[1]][ini[2]][ini[3]][ini[4]]=1.0;
    for(int x=0;x<=n;x++)
        for(int now1=1;now1<=8;now1++)
            for(int now2=1;now2<=8;now2++)
                for(int now3=1;now3<=8;now3++)
                    for(int now4=1;now4<=8;now4++)
                        work(x,now1,now2,now3,now4);

    for(int now1=1;now1<=8;now1++)
        for(int now2=1;now2<=8;now2++)
            for(int now3=1;now3<=8;now3++)
                for(int now4=1;now4<=8;now4++)
                {
                    ans[1][lev[1][now1]]+=dp[n+1][now1][now2][now3][now4];
                    ans[2][lev[2][now2]]+=dp[n+1][now1][now2][now3][now4];
                    ans[3][lev[3][now3]]+=dp[n+1][now1][now2][now3][now4];
                    ans[4][lev[4][now4]]+=dp[n+1][now1][now2][now3][now4];
                }
    printf("%.2lf\n",dead*100);
    for(int i=1;i<=4;i++)
    {
        for(int j=1;j<=8;j++)
            printf("%.2lf ",ans[i][j]*100);
        putchar('\n');
    }
    return 0;
}

rp++

posted @ 2019-10-27 11:16  HEOI-动动  阅读(701)  评论(0编辑  收藏  举报