今天的主人公是什么?
60.1K!!!!
先扔代码再更新防止我等会儿一上头不打算写完题解
T1:
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; const double inf=214748364; int n,k; double a[100010],f[21][100010]; int main() { scanf("%d%d",&n,&k); for(int i=1;i<=n;i++)scanf("%lf",&a[i]); sort(a+1,a+n+1); n=unique(a+1,a+n+1)-a-1; for(int i=0;i<=n;i++){ for(int j=0;j<=k;j++)f[j][i]=inf; } f[0][0]=0; for(int i=1;i<=n;i++){ for(int j=1;j<=k;j++){ for(int l=1;l<=i;l++){ f[j][i]=min(f[j][i],f[j-1][l-1]+(a[i]-a[l])*(a[i]-a[l])); } } } if(k>=n)printf("0.00\n"); else printf("%.2lf\n",f[k][n]); return 0; }
T2:
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> using namespace std; int val[5][10],a[5],n,opt,num,goal,sum; double p[20][20][20][20],dice[10][20],ans[5][10],b[20][20][20][20]; char s[5][10]; int main() { // freopen("1.out","w",stdout); for(int i=1;i<=4;i++){ for(int j=1;j<=8;j++)scanf("%1d",&val[i][j]); scanf("%d",&a[i]); } p[a[1]][a[2]][a[3]][a[4]]=1; dice[0][0]=1; scanf("%d",&n); for(int i=1;i<=8;i++){ for(int j=0;j<=(i<<1);j++){ dice[i][j]=(dice[i-1][j]/3.00); if(j)dice[i][j]+=(dice[i-1][j-1]/3.00); if(j>=1)dice[i][j]+=(dice[i-1][j-2]/3.00); } } for(int i=1;i<=n;i++){ memset(s[0],0,sizeof(s[0])); memset(s[1],0,sizeof(s[1])); memset(s[2],0,sizeof(s[2])); memset(s[3],0,sizeof(s[3])); scanf("%s%s",s[0],s[1]); if(s[1][0]==‘<‘||s[1][0]==‘>‘){ int x; scanf("%d",&x); scanf("%s%s",s[2],s[3]); if(s[1][0]==‘<‘){ if(s[1][1]==‘=‘){ if(s[0][1]==‘i‘)opt=1; else if(s[0][1]==‘p‘)opt=2; else if(s[0][1]==‘a‘)opt=3; else opt=4; if(s[2][1]==‘i‘)goal=1; else if(s[2][1]==‘p‘)goal=2; else if(s[2][1]==‘a‘)goal=3; else goal=4; if(s[3][0]==‘+‘)num=s[3][1]-‘0‘; else num=-(s[3][1]-‘0‘); if(s[3][2]==‘?‘){//<=? for(int a1=1;a1<=8;a1++){ for(int b1=1;b1<=8;b1++){ for(int c1=1;c1<=8;c1++){ for(int d1=1;d1<=8;d1++){ for(int l=0;l<=((abs(num))<<1);l++){ if(opt==1){ for(int k=0;k<=(val[1][a1]<<1);k++){ if(k<=x){ if(goal==1){ if(a1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else if(a1+(num<0?-1:1)*l>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else b[a1+(num<0?-1:1)*l][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; } else if(goal==2){ if(b1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else if(b1+(num<0?-1:1)*l>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else b[a1][b1+(num<0?-1:1)*l][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; } else if(goal==3){ if(c1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else if(c1+(num<0?-1:1)*l>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else b[a1][b1][c1+(num<0?-1:1)*l][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; } else{ if(d1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else if(d1+(num<0?-1:1)*l>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else b[a1][b1][c1][d1+(num<0?-1:1)*l]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]*dice[abs(num)][l]; } } } else if(opt==2){ for(int k=0;k<=(val[2][b1]<<1);k++){ if(k<=x){ if(goal==1){ if(a1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else if(a1+(num<0?-1:1)*l>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else b[a1+(num<0?-1:1)*l][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; } else if(goal==2){ if(b1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else if(b1+(num<0?-1:1)*l>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else b[a1][b1+(num<0?-1:1)*l][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; } else if(goal==3){ if(c1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else if(c1+(num<0?-1:1)*l>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else b[a1][b1][c1+(num<0?-1:1)*l][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; } else{ if(d1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else if(d1+(num<0?-1:1)*l>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else b[a1][b1][c1][d1+(num<0?-1:1)*l]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]*dice[abs(num)][l]; } } } else if(opt==3){ for(int k=0;k<=(val[3][c1]<<1);k++){ if(k<=x){ if(goal==1){ if(a1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else if(a1+(num<0?-1:1)*l>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else b[a1+(num<0?-1:1)*l][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; } else if(goal==2){ if(b1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else if(b1+(num<0?-1:1)*l>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else b[a1][b1+(num<0?-1:1)*l][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; } else if(goal==3){ if(c1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else if(c1+(num<0?-1:1)*l>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else b[a1][b1][c1+(num<0?-1:1)*l][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; } else{ if(d1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else if(d1+(num<0?-1:1)*l>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else b[a1][b1][c1][d1+(num<0?-1:1)*l]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]*dice[abs(num)][l]; } } } else{ for(int k=0;k<=(val[4][d1]<<1);k++){ if(k<=x){ if(goal==1){ if(a1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else if(a1+(num<0?-1:1)*l>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else b[a1+(num<0?-1:1)*l][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; } else if(goal==2){ if(b1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else if(b1+(num<0?-1:1)*l>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else b[a1][b1+(num<0?-1:1)*l][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; } else if(goal==3){ if(c1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else if(c1+(num<0?-1:1)*l>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else b[a1][b1][c1+(num<0?-1:1)*l][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; } else{ if(d1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else if(d1+(num<0?-1:1)*l>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else b[a1][b1][c1][d1+(num<0?-1:1)*l]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]*dice[abs(num)][l]; } } } } } } } } } else{//<=x for(int a1=1;a1<=8;a1++){ for(int b1=1;b1<=8;b1++){ for(int c1=1;c1<=8;c1++){ for(int d1=1;d1<=8;d1++){ if(opt==1){ for(int k=0;k<=(val[1][a1]<<1);k++){ if(k<=x){ if(goal==1){ if(a1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else if(a1+num>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else b[a1+num][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; } else if(goal==2){ if(b1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else if(b1+num>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else b[a1][b1+num][c1][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; } else if(goal==3){ if(c1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else if(c1+num>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else b[a1][b1][c1+num][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; } else{ if(d1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else if(d1+num>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else b[a1][b1][c1][d1+num]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; } } } else if(opt==2){ for(int k=0;k<=(val[2][b1]<<1);k++){ if(k<=x){ if(goal==1){ if(a1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else if(a1+num>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else b[a1+num][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; } else if(goal==2){ if(b1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else if(b1+num>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else b[a1][b1+num][c1][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; } else if(goal==3){ if(c1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else if(c1+num>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else b[a1][b1][c1+num][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; } else{ if(d1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else if(d1+num>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else b[a1][b1][c1][d1+num]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; } } } else if(opt==3){ for(int k=0;k<=(val[3][c1]<<1);k++){ if(k<=x){ if(goal==1){ if(a1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else if(a1+num>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else b[a1+num][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; } else if(goal==2){ if(b1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else if(b1+num>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else b[a1][b1+num][c1][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; } else if(goal==3){ if(c1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else if(c1+num>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else b[a1][b1][c1+num][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; } else{ if(d1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else if(d1+num>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else b[a1][b1][c1][d1+num]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; } } } else{ for(int k=0;k<=(val[4][d1]<<1);k++){ if(k<=x){ if(goal==1){ if(a1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else if(a1+num>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else b[a1+num][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; } else if(goal==2){ if(b1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else if(b1+num>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else b[a1][b1+num][c1][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; } else if(goal==3){ if(c1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else if(c1+num>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else b[a1][b1][c1+num][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; } else{ if(d1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else if(d1+num>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else b[a1][b1][c1][d1+num]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; } } } } } } } } } else{ if(s[0][1]==‘i‘)opt=1; else if(s[0][1]==‘p‘)opt=2; else if(s[0][1]==‘a‘)opt=3; else opt=4; if(s[2][1]==‘i‘)goal=1; else if(s[2][1]==‘p‘)goal=2; else if(s[2][1]==‘a‘)goal=3; else goal=4; if(s[3][0]==‘+‘)num=s[3][1]-‘0‘; else num=-(s[3][1]-‘0‘); if(s[3][2]==‘?‘){//<? for(int a1=1;a1<=8;a1++){ for(int b1=1;b1<=8;b1++){ for(int c1=1;c1<=8;c1++){ for(int d1=1;d1<=8;d1++){ for(int l=0;l<=((abs(num))<<1);l++){ if(opt==1){ for(int k=0;k<=(val[1][a1]<<1);k++){ if(k<x){ if(goal==1){ if(a1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else if(a1+(num<0?-1:1)*l>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else b[a1+(num<0?-1:1)*l][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; } else if(goal==2){ if(b1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else if(b1+(num<0?-1:1)*l>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else b[a1][b1+(num<0?-1:1)*l][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; } else if(goal==3){ if(c1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else if(c1+(num<0?-1:1)*l>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else b[a1][b1][c1+(num<0?-1:1)*l][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; } else{ if(d1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else if(d1+(num<0?-1:1)*l>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else b[a1][b1][c1][d1+(num<0?-1:1)*l]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]*dice[abs(num)][l]; } } } else if(opt==2){ for(int k=0;k<=(val[2][b1]<<1);k++){ if(k<x){ if(goal==1){ if(a1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else if(a1+(num<0?-1:1)*l>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else b[a1+(num<0?-1:1)*l][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; } else if(goal==2){ if(b1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else if(b1+(num<0?-1:1)*l>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else b[a1][b1+(num<0?-1:1)*l][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; } else if(goal==3){ if(c1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else if(c1+(num<0?-1:1)*l>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else b[a1][b1][c1+(num<0?-1:1)*l][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; } else{ if(d1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else if(d1+(num<0?-1:1)*l>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else b[a1][b1][c1][d1+(num<0?-1:1)*l]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]*dice[abs(num)][l]; } } } else if(opt==3){ for(int k=0;k<=(val[3][c1]<<1);k++){ if(k<x){ if(goal==1){ if(a1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else if(a1+(num<0?-1:1)*l>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else b[a1+(num<0?-1:1)*l][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; } else if(goal==2){ if(b1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else if(b1+(num<0?-1:1)*l>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else b[a1][b1+(num<0?-1:1)*l][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; } else if(goal==3){ if(c1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else if(c1+(num<0?-1:1)*l>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else b[a1][b1][c1+(num<0?-1:1)*l][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; } else{ if(d1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else if(d1+(num<0?-1:1)*l>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else b[a1][b1][c1][d1+(num<0?-1:1)*l]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]*dice[abs(num)][l]; } } } else{ for(int k=0;k<=(val[4][d1]<<1);k++){ if(k<x){ if(goal==1){ if(a1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else if(a1+(num<0?-1:1)*l>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else b[a1+(num<0?-1:1)*l][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; } else if(goal==2){ if(b1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else if(b1+(num<0?-1:1)*l>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else b[a1][b1+(num<0?-1:1)*l][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; } else if(goal==3){ if(c1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else if(c1+(num<0?-1:1)*l>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else b[a1][b1][c1+(num<0?-1:1)*l][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; } else{ if(d1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else if(d1+(num<0?-1:1)*l>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else b[a1][b1][c1][d1+(num<0?-1:1)*l]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]*dice[abs(num)][l]; } } } } } } } } } else{//<x for(int a1=1;a1<=8;a1++){ for(int b1=1;b1<=8;b1++){ for(int c1=1;c1<=8;c1++){ for(int d1=1;d1<=8;d1++){ if(opt==1){ for(int k=0;k<=(val[1][a1]<<1);k++){ if(k<x){ if(goal==1){ if(a1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else if(a1+num>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else b[a1+num][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; } else if(goal==2){ if(b1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else if(b1+num>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else b[a1][b1+num][c1][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; } else if(goal==3){ if(c1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else if(c1+num>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else b[a1][b1][c1+num][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; } else{ if(d1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else if(d1+num>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else b[a1][b1][c1][d1+num]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; } } } else if(opt==2){ for(int k=0;k<=(val[2][b1]<<1);k++){ if(k<x){ if(goal==1){ if(a1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else if(a1+num>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else b[a1+num][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; } else if(goal==2){ if(b1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else if(b1+num>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else b[a1][b1+num][c1][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; } else if(goal==3){ if(c1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else if(c1+num>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else b[a1][b1][c1+num][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; } else{ if(d1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else if(d1+num>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else b[a1][b1][c1][d1+num]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; } } } else if(opt==3){ for(int k=0;k<=(val[3][c1]<<1);k++){ if(k<x){ if(goal==1){ if(a1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else if(a1+num>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else b[a1+num][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; } else if(goal==2){ if(b1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else if(b1+num>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else b[a1][b1+num][c1][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; } else if(goal==3){ if(c1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else if(c1+num>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else b[a1][b1][c1+num][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; } else{ if(d1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else if(d1+num>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else b[a1][b1][c1][d1+num]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; } } } else{ for(int k=0;k<=(val[4][d1]<<1);k++){ if(k<x){ if(goal==1){ if(a1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else if(a1+num>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else b[a1+num][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; } else if(goal==2){ if(b1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else if(b1+num>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else b[a1][b1+num][c1][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; } else if(goal==3){ if(c1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else if(c1+num>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else b[a1][b1][c1+num][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; } else{ if(d1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else if(d1+num>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else b[a1][b1][c1][d1+num]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; } } } } } } } } } } else{ if(s[1][1]==‘=‘){ if(s[0][1]==‘i‘)opt=1; else if(s[0][1]==‘p‘)opt=2; else if(s[0][1]==‘a‘)opt=3; else opt=4; if(s[2][1]==‘i‘)goal=1; else if(s[2][1]==‘p‘)goal=2; else if(s[2][1]==‘a‘)goal=3; else goal=4; if(s[3][0]==‘+‘)num=s[3][1]-‘0‘; else num=-(s[3][1]-‘0‘); if(s[3][2]==‘?‘){//>=? for(int a1=1;a1<=8;a1++){ for(int b1=1;b1<=8;b1++){ for(int c1=1;c1<=8;c1++){ for(int d1=1;d1<=8;d1++){ for(int l=0;l<=((abs(num))<<1);l++){ if(opt==1){ for(int k=0;k<=(val[1][a1]<<1);k++){ if(k>=x){ if(goal==1){ if(a1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else if(a1+(num<0?-1:1)*l>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else b[a1+(num<0?-1:1)*l][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; } else if(goal==2){ if(b1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else if(b1+(num<0?-1:1)*l>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else b[a1][b1+(num<0?-1:1)*l][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; } else if(goal==3){ if(c1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else if(c1+(num<0?-1:1)*l>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else b[a1][b1][c1+(num<0?-1:1)*l][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; } else{ if(d1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else if(d1+(num<0?-1:1)*l>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else b[a1][b1][c1][d1+(num<0?-1:1)*l]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]*dice[abs(num)][l]; } } } else if(opt==2){ for(int k=0;k<=(val[2][b1]<<1);k++){ if(k>=x){ if(goal==1){ if(a1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else if(a1+(num<0?-1:1)*l>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else b[a1+(num<0?-1:1)*l][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; } else if(goal==2){ if(b1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else if(b1+(num<0?-1:1)*l>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else b[a1][b1+(num<0?-1:1)*l][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; } else if(goal==3){ if(c1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else if(c1+(num<0?-1:1)*l>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else b[a1][b1][c1+(num<0?-1:1)*l][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; } else{ if(d1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else if(d1+(num<0?-1:1)*l>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else b[a1][b1][c1][d1+(num<0?-1:1)*l]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]*dice[abs(num)][l]; } } } else if(opt==3){ for(int k=0;k<=(val[3][c1]<<1);k++){ if(k>=x){ if(goal==1){ if(a1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else if(a1+(num<0?-1:1)*l>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else b[a1+(num<0?-1:1)*l][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; } else if(goal==2){ if(b1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else if(b1+(num<0?-1:1)*l>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else b[a1][b1+(num<0?-1:1)*l][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; } else if(goal==3){ if(c1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else if(c1+(num<0?-1:1)*l>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else b[a1][b1][c1+(num<0?-1:1)*l][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; } else{ if(d1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else if(d1+(num<0?-1:1)*l>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else b[a1][b1][c1][d1+(num<0?-1:1)*l]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]*dice[abs(num)][l]; } } } else{ for(int k=0;k<=(val[4][d1]<<1);k++){ if(k>=x){ if(goal==1){ if(a1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else if(a1+(num<0?-1:1)*l>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else b[a1+(num<0?-1:1)*l][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; } else if(goal==2){ if(b1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else if(b1+(num<0?-1:1)*l>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else b[a1][b1+(num<0?-1:1)*l][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; } else if(goal==3){ if(c1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else if(c1+(num<0?-1:1)*l>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else b[a1][b1][c1+(num<0?-1:1)*l][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; } else{ if(d1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else if(d1+(num<0?-1:1)*l>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else b[a1][b1][c1][d1+(num<0?-1:1)*l]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]*dice[abs(num)][l]; } } } } } } } } } else{//>=x for(int a1=1;a1<=8;a1++){ for(int b1=1;b1<=8;b1++){ for(int c1=1;c1<=8;c1++){ for(int d1=1;d1<=8;d1++){ if(opt==1){ for(int k=0;k<=(val[1][a1]<<1);k++){ if(k>=x){ if(goal==1){ if(a1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else if(a1+num>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else b[a1+num][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; } else if(goal==2){ if(b1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else if(b1+num>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else b[a1][b1+num][c1][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; } else if(goal==3){ if(c1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else if(c1+num>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else b[a1][b1][c1+num][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; } else{ if(d1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else if(d1+num>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else b[a1][b1][c1][d1+num]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; } } } else if(opt==2){ for(int k=0;k<=(val[2][b1]<<1);k++){ if(k>=x){ if(goal==1){ if(a1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else if(a1+num>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else b[a1+num][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; } else if(goal==2){ if(b1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else if(b1+num>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else b[a1][b1+num][c1][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; } else if(goal==3){ if(c1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else if(c1+num>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else b[a1][b1][c1+num][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; } else{ if(d1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else if(d1+num>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else b[a1][b1][c1][d1+num]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; } } } else if(opt==3){ for(int k=0;k<=(val[3][c1]<<1);k++){ if(k>=x){ if(goal==1){ if(a1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else if(a1+num>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else b[a1+num][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; } else if(goal==2){ if(b1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else if(b1+num>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else b[a1][b1+num][c1][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; } else if(goal==3){ if(c1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else if(c1+num>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else b[a1][b1][c1+num][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; } else{ if(d1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else if(d1+num>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else b[a1][b1][c1][d1+num]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; } } } else{ for(int k=0;k<=(val[4][d1]<<1);k++){ if(k>=x){ if(goal==1){ if(a1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else if(a1+num>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else b[a1+num][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; } else if(goal==2){ if(b1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else if(b1+num>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else b[a1][b1+num][c1][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; } else if(goal==3){ if(c1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else if(c1+num>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else b[a1][b1][c1+num][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; } else{ if(d1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else if(d1+num>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else b[a1][b1][c1][d1+num]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; } } } } } } } } } else{ if(s[0][1]==‘i‘)opt=1; else if(s[0][1]==‘p‘)opt=2; else if(s[0][1]==‘a‘)opt=3; else opt=4; if(s[2][1]==‘i‘)goal=1; else if(s[2][1]==‘p‘)goal=2; else if(s[2][1]==‘a‘)goal=3; else goal=4; if(s[3][0]==‘+‘)num=s[3][1]-‘0‘; else num=-(s[3][1]-‘0‘); if(s[3][2]==‘?‘){//>? for(int a1=1;a1<=8;a1++){ for(int b1=1;b1<=8;b1++){ for(int c1=1;c1<=8;c1++){ for(int d1=1;d1<=8;d1++){ for(int l=0;l<=((abs(num))<<1);l++){ if(opt==1){ for(int k=0;k<=(val[1][a1]<<1);k++){ if(k>x){ if(goal==1){ if(a1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else if(a1+(num<0?-1:1)*l>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else b[a1+(num<0?-1:1)*l][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; } else if(goal==2){ if(b1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else if(b1+(num<0?-1:1)*l>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else b[a1][b1+(num<0?-1:1)*l][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; } else if(goal==3){ if(c1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else if(c1+(num<0?-1:1)*l>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else b[a1][b1][c1+(num<0?-1:1)*l][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; } else{ if(d1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else if(d1+(num<0?-1:1)*l>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; else b[a1][b1][c1][d1+(num<0?-1:1)*l]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[1][a1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]*dice[abs(num)][l]; } } } else if(opt==2){ for(int k=0;k<=(val[2][b1]<<1);k++){ if(k>x){ if(goal==1){ if(a1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else if(a1+(num<0?-1:1)*l>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else b[a1+(num<0?-1:1)*l][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; } else if(goal==2){ if(b1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else if(b1+(num<0?-1:1)*l>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else b[a1][b1+(num<0?-1:1)*l][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; } else if(goal==3){ if(c1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else if(c1+(num<0?-1:1)*l>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else b[a1][b1][c1+(num<0?-1:1)*l][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; } else{ if(d1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else if(d1+(num<0?-1:1)*l>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; else b[a1][b1][c1][d1+(num<0?-1:1)*l]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[2][b1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]*dice[abs(num)][l]; } } } else if(opt==3){ for(int k=0;k<=(val[3][c1]<<1);k++){ if(k>x){ if(goal==1){ if(a1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else if(a1+(num<0?-1:1)*l>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else b[a1+(num<0?-1:1)*l][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; } else if(goal==2){ if(b1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else if(b1+(num<0?-1:1)*l>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else b[a1][b1+(num<0?-1:1)*l][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; } else if(goal==3){ if(c1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else if(c1+(num<0?-1:1)*l>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else b[a1][b1][c1+(num<0?-1:1)*l][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; } else{ if(d1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else if(d1+(num<0?-1:1)*l>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; else b[a1][b1][c1][d1+(num<0?-1:1)*l]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[3][c1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]*dice[abs(num)][l]; } } } else{ for(int k=0;k<=(val[4][d1]<<1);k++){ if(k>x){ if(goal==1){ if(a1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else if(a1+(num<0?-1:1)*l>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else b[a1+(num<0?-1:1)*l][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; } else if(goal==2){ if(b1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else if(b1+(num<0?-1:1)*l>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else b[a1][b1+(num<0?-1:1)*l][c1][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; } else if(goal==3){ if(c1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else if(c1+(num<0?-1:1)*l>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else b[a1][b1][c1+(num<0?-1:1)*l][d1]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; } else{ if(d1+(num<0?-1:1)*l<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else if(d1+(num<0?-1:1)*l>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; else b[a1][b1][c1][d1+(num<0?-1:1)*l]+=p[a1][b1][c1][d1]*dice[abs(num)][l]*dice[val[4][d1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]*dice[abs(num)][l]; } } } } } } } } } else{//>x for(int a1=1;a1<=8;a1++){ for(int b1=1;b1<=8;b1++){ for(int c1=1;c1<=8;c1++){ for(int d1=1;d1<=8;d1++){ if(opt==1){ for(int k=0;k<=(val[1][a1]<<1);k++){ if(k>x){ if(goal==1){ if(a1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else if(a1+num>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else b[a1+num][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; } else if(goal==2){ if(b1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else if(b1+num>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else b[a1][b1+num][c1][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; } else if(goal==3){ if(c1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else if(c1+num>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else b[a1][b1][c1+num][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; } else{ if(d1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else if(d1+num>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; else b[a1][b1][c1][d1+num]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[1][a1]][k]; } } } else if(opt==2){ for(int k=0;k<=(val[2][b1]<<1);k++){ if(k>x){ if(goal==1){ if(a1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else if(a1+num>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else b[a1+num][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; } else if(goal==2){ if(b1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else if(b1+num>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else b[a1][b1+num][c1][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; } else if(goal==3){ if(c1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else if(c1+num>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else b[a1][b1][c1+num][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; } else{ if(d1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else if(d1+num>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; else b[a1][b1][c1][d1+num]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[2][b1]][k]; } } } else if(opt==3){ for(int k=0;k<=(val[3][c1]<<1);k++){ if(k>x){ if(goal==1){ if(a1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else if(a1+num>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else b[a1+num][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; } else if(goal==2){ if(b1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else if(b1+num>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else b[a1][b1+num][c1][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; } else if(goal==3){ if(c1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else if(c1+num>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else b[a1][b1][c1+num][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; } else{ if(d1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else if(d1+num>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; else b[a1][b1][c1][d1+num]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[3][c1]][k]; } } } else{ for(int k=0;k<=(val[4][d1]<<1);k++){ if(k>x){ if(goal==1){ if(a1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else if(a1+num>=8)b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else b[a1+num][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; } else if(goal==2){ if(b1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else if(b1+num>=8)b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else b[a1][b1+num][c1][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; } else if(goal==3){ if(c1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else if(c1+num>=8)b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else b[a1][b1][c1+num][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; } else{ if(d1+num<=0)b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else if(d1+num>=8)b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; else b[a1][b1][c1][d1+num]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; } } else{ b[a1][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[val[4][d1]][k]; } } } } } } } } } } for(int a1=0;a1<=8;a1++){ for(int b1=0;b1<=8;b1++){ for(int c1=0;c1<=8;c1++){ for(int d1=0;d1<=8;d1++){ p[a1][b1][c1][d1]=b[a1][b1][c1][d1]; b[a1][b1][c1][d1]=0; // printf("%d %d %d %d %lf\n",a1,b1,c1,d1,p[a1][b1][c1][d1]); } } } } b[0][0][0][0]=p[0][0][0][0]; } else{ if(s[1][2]==‘?‘){ if(s[0][1]==‘i‘)opt=1; else if(s[0][1]==‘p‘)opt=2; else if(s[0][1]==‘a‘)opt=3; else opt=4; if(s[1][0]==‘+‘)num=s[1][1]-‘0‘; else num=-(s[1][1]-‘0‘); if(num<0){ num=-num; for(int a1=1;a1<=8;a1++){ for(int b1=1;b1<=8;b1++){ for(int c1=1;c1<=8;c1++){ for(int d1=1;d1<=8;d1++){ for(int l=0;l<=(num<<1);l++){ if(opt==1){ if(a1-l>0)b[a1-l][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[num][l]; else b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[num][l]; } else if(opt==2){ if(b1-l>0)b[a1][b1-l][c1][d1]+=p[a1][b1][c1][d1]*dice[num][l]; else b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[num][l]; } else if(opt==3){ if(c1-l>0)b[a1][b1][c1-l][d1]+=p[a1][b1][c1][d1]*dice[num][l]; else b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[num][l]; } else{ if(d1-l>0)b[a1][b1][c1][d1-l]+=p[a1][b1][c1][d1]*dice[num][l]; else b[0][0][0][0]+=p[a1][b1][c1][d1]*dice[num][l]; } } } } } } } else{ for(int a1=8;a1>=1;a1--){ for(int b1=8;b1>=1;b1--){ for(int c1=8;c1>=1;c1--){ for(int d1=8;d1>=1;d1--){ for(int l=0;l<=(num<<1);l++){ if(opt==1){ if(a1+l<=8)b[a1+l][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[num][l]; else b[8][b1][c1][d1]+=p[a1][b1][c1][d1]*dice[num][l]; } else if(opt==2){ if(b1+l<=8)b[a1][b1+l][c1][d1]+=p[a1][b1][c1][d1]*dice[num][l]; else b[a1][8][c1][d1]+=p[a1][b1][c1][d1]*dice[num][l]; } else if(opt==3){ if(c1+l<=8)b[a1][b1][c1+l][d1]+=p[a1][b1][c1][d1]*dice[num][l]; else b[a1][b1][8][d1]+=p[a1][b1][c1][d1]*dice[num][l]; } else{ if(d1+l<=8)b[a1][b1][c1][d1+l]+=p[a1][b1][c1][d1]*dice[num][l]; else b[a1][b1][c1][8]+=p[a1][b1][c1][d1]*dice[num][l]; } } } } } } } } else{ if(s[0][1]==‘i‘)opt=1; else if(s[0][1]==‘p‘)opt=2; else if(s[0][1]==‘a‘)opt=3; else opt=4; if(s[1][0]==‘+‘)num=s[1][1]-‘0‘; else num=-(s[1][1]-‘0‘); if(num<0){ for(int a1=1;a1<=8;a1++){ for(int b1=1;b1<=8;b1++){ for(int c1=1;c1<=8;c1++){ for(int d1=1;d1<=8;d1++){ if(opt==1){ if(a1+num>0)b[a1+num][b1][c1][d1]+=p[a1][b1][c1][d1]; else b[0][0][0][0]+=p[a1][b1][c1][d1]; } else if(opt==2){ if(b1+num>0)b[a1][b1+num][c1][d1]+=p[a1][b1][c1][d1]; else b[0][0][0][0]+=p[a1][b1][c1][d1]; } else if(opt==3){ if(c1+num>0)b[a1][b1][c1+num][d1]+=p[a1][b1][c1][d1]; else b[0][0][0][0]+=p[a1][b1][c1][d1]; } else{ if(d1+num>0)b[a1][b1][c1][d1+num]+=p[a1][b1][c1][d1]; else b[0][0][0][0]+=p[a1][b1][c1][d1]; } } } } } } else{ for(int a1=8;a1>=1;a1--){ for(int b1=8;b1>=1;b1--){ for(int c1=8;c1>=1;c1--){ for(int d1=8;d1>=1;d1--){ if(opt==1){ if(a1+num<=8)b[a1+num][b1][c1][d1]+=p[a1][b1][c1][d1]; else b[8][b1][c1][d1]+=p[a1][b1][c1][d1]; } else if(opt==2){ if(b1+num<=8)b[a1][b1+num][c1][d1]+=p[a1][b1][c1][d1]; else b[a1][8][c1][d1]+=p[a1][b1][c1][d1]; } else if(opt==3){ if(c1+num<=8)b[a1][b1][c1+num][d1]+=p[a1][b1][c1][d1]; else b[a1][b1][8][d1]+=p[a1][b1][c1][d1]; } else{ if(d1+num<=8)b[a1][b1][c1][d1+num]+=p[a1][b1][c1][d1]; else b[a1][b1][c1][8]+=p[a1][b1][c1][d1]; } } } } } } } for(int a1=0;a1<=8;a1++){ for(int b1=0;b1<=8;b1++){ for(int c1=0;c1<=8;c1++){ for(int d1=0;d1<=8;d1++){ p[a1][b1][c1][d1]=b[a1][b1][c1][d1]; b[a1][b1][c1][d1]=0; // printf("%d %d %d %d %lf\n",a1,b1,c1,d1,p[a1][b1][c1][d1]); } } } } b[0][0][0][0]=p[0][0][0][0]; } } printf("%.2lf\n",p[0][0][0][0]*100.0); for(int a1=1;a1<=8;a1++){ for(int b1=1;b1<=8;b1++){ for(int c1=1;c1<=8;c1++){ for(int d1=1;d1<=8;d1++){ ans[1][val[1][a1]]+=p[a1][b1][c1][d1]; ans[2][val[2][b1]]+=p[a1][b1][c1][d1]; ans[3][val[3][c1]]+=p[a1][b1][c1][d1]; ans[4][val[4][d1]]+=p[a1][b1][c1][d1]; } } } } for(int i=1;i<=4;i++){ for(int j=1;j<=8;j++){ printf("%.2lf ",ans[i][j]*100.0); } printf("\n"); } return 0; }
最好不要点开,关爱眼睛
T3:
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int n; int k[15],cnt[5],vis[15][15][15][4]; struct node{ int d[1010],len; }f[15][15][15][4],fir; node cheng(node x,int sum){ node e; memset(e.d,0,sizeof(e.d)); e.len=x.len; for(int i=1;i<=x.len;i++){ e.d[i]+=x.d[i]*sum; e.d[i+1]+=e.d[i]/10; e.d[i]%=10; } while(e.d[e.len+1])e.len++; return e; } node jia(node x,node y){ node e; memset(e.d,0,sizeof(e.d)); e.len=max(x.len,y.len); for(int i=1;i<=e.len;i++){ e.d[i]+=x.d[i]+y.d[i]; e.d[i+1]+=e.d[i]/10; e.d[i]%=10; } while(e.d[e.len+1])e.len++; return e; } node dfs(int x,int y,int z,int lst){ if(!x&&!y&&!z)return fir; if(vis[x][y][z][lst])return f[x][y][z][lst]; vis[x][y][z][lst]=1; node num; memset(num.d,0,sizeof(num.d)); num.len=0; if(x){ num=jia(num,cheng(dfs(x-1,y,z,1),x-(lst==2))); } if(y){ num=jia(num,cheng(dfs(x+1,y-1,z,2),y-(lst==3))); } if(z){ num=jia(num,cheng(dfs(x,y+1,z-1,3),z)); } return f[x][y][z][lst]=num; } int main() { scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&k[i]); cnt[k[i]]++; } memset(fir.d,0,sizeof(fir.d)); fir.len=fir.d[1]=1; node ans=dfs(cnt[1],cnt[2],cnt[3],0); for(int i=ans.len;i>=1;i--){ printf("%d",ans.d[i]); } return 0; }
果然不想写题解了【瘫】
原文地址:https://www.cnblogs.com/chloris/p/11744014.html
时间: 2024-11-02 22:11:43