#include<bits/stdc++.h>
using namespace std;
inline int read(){
int s=0,w=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
return s*w;
}
int A,B,C,D;double f[15][15][15][15][5][5];
inline bool check(int a,int b,int c,int d,int x,int y){
if(x==1)a++;else if(x==2)b++;else if(x==3)c++;else if(x==4)d++;
if(y==1)a++;else if(y==2)b++;else if(y==3)c++;else if(y==4)d++;
if(a>=A&&b>=B&&c>=C&&d>=D)return true;else return false;
}
inline double dfs(int a,int b,int c,int d,int x,int y){
double &ans=f[a][b][c][d][x][y];
if(ans)return f[a][b][c][d][x][y];
if(check(a,b,c,d,x,y))return 0;
int rest=54-(a+b+c+d+(x>0)+(y>0));
if(a<13)ans+=dfs(a+1,b,c,d,x,y)*(13-a)/rest;
if(b<13)ans+=dfs(a,b+1,c,d,x,y)*(13-b)/rest;
if(c<13)ans+=dfs(a,b,c+1,d,x,y)*(13-c)/rest;
if(d<13)ans+=dfs(a,b,c,d+1,x,y)*(13-d)/rest;
if(!x)ans+=min(min(dfs(a,b,c,d,1,y),dfs(a,b,c,d,2,y)),min(dfs(a,b,c,d,3,y),dfs(a,b,c,d,4,y)))/rest;
if(!y)ans+=min(min(dfs(a,b,c,d,x,1),dfs(a,b,c,d,x,2)),min(dfs(a,b,c,d,x,3),dfs(a,b,c,d,x,4)))/rest;
return ++ans;
}
int main(){
A=read(),B=read(),C=read(),D=read();int bj=0;
if(A>13)bj+=A-13;if(B>13)bj+=B-13;if(C>13)bj+=C-13;if(D>13)bj+=D-13;
if(bj>2)puts("-1.000");
else printf("%.3lf\n",dfs(0,0,0,0,0,0));
return 0;
}
原文:https://www.cnblogs.com/PPXppx/p/10993792.html