版权声明:作为一个蒟蒻,转载时请通知我这个蒟蒻 https://blog.csdn.net/zyszlb2003/article/details/89842010
题面描述
思路
设
为小王、大王,
,黑桃,
,红桃,
,梅花,
,方块。
,表示还没放.
方程:
AC code
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
using namespace std;
const double inf=0x3f3f3f3f;
double f[15][15][15][15][5][5];
bool v[15][15][15][15][5][5];
int A,B,C,D;
void add(int x,int &a,int &b,int &c,int &d)
{
if(x==1)a++;
else if(x==2)b++;
else if(x==3)c++;
else if(x==4)d++;
}
double dfs(int a,int b,int c,int d,int x,int y)
{
if(v[a][b][c][d][x][y])return f[a][b][c][d][x][y];
v[a][b][c][d][x][y]=1;
double &s=f[a][b][c][d][x][y]=0;
int na=a,nb=b,nc=c,nd=d;
add(x,na,nb,nc,nd);add(y,na,nb,nc,nd);
if(na>=A&&nb>=B&&nc>=C&&nd>=D)return 0;
int w=54-na-nb-nc-nd;
if(w<=0)return s=inf;
if(a<13)s+=dfs(a+1,b,c,d,x,y)*(13-a)/w;
if(b<13)s+=dfs(a,b+1,c,d,x,y)*(13-b)/w;
if(c<13)s+=dfs(a,b,c+1,d,x,y)*(13-c)/w;
if(d<13)s+=dfs(a,b,c,d+1,x,y)*(13-d)/w;
if(!x)s+=min(dfs(a,b,c,d,1,y),min(dfs(a,b,c,d,2,y),min(dfs(a,b,c,d,3,y),dfs(a,b,c,d,4,y))))/w;
if(!y)s+=min(dfs(a,b,c,d,x,1),min(dfs(a,b,c,d,x,2),min(dfs(a,b,c,d,x,3),dfs(a,b,c,d,x,4))))/w;
return ++s;
}
int main()
{
scanf("%d%d%d%d",&A,&B,&C,&D);
int t=((A>13)?A-13:0)+((B>13)?B-13:0)+((C>13)?C-13:0)+((D>13)?D-13:0);
if(t>2)puts("-1.000");
else printf("%.3lf\n",dfs(0,0,0,0,0,0));
return 0;
}