题面描述
思路
设
x
,
y
x,y
x,y为小王、大王,
x
=
1
x=1
x=1,黑桃,
x
=
2
x=2
x=2,红桃,
x
=
3
x=3
x=3,梅花,
x
=
4
x=4
x=4,方块。
x
=
0
x=0
x=0,表示还没放.
方程:
f
[
a
,
b
,
c
,
d
,
x
,
y
]
=
f[a,b,c,d,x,y]=
f[a,b,c,d,x,y]=
13 − a 54 − s u m ∗ f [ a + 1 , b , c , d , x , y ] + 13 − b 54 − s u m ∗ f [ a , b + 1 , c , d , x , y ] + \frac{13-a}{54-sum}*f[a+1,b,c,d,x,y]+\frac{13-b}{54-sum}*f[a,b+1,c,d,x,y]+ 54−sum13−a∗f[a+1,b,c,d,x,y]+54−sum13−b∗f[a,b+1,c,d,x,y]+
13 − c 54 − s u m ∗ f [ a , b , c + 1 , d , x , y ] + 13 − d 54 − s u m ∗ f [ a , b , c , d + 1 , x , y ] + \frac{13-c}{54-sum}*f[a,b,c+1,d,x,y]+\frac{13-d}{54-sum}*f[a,b,c,d+1,x,y]+ 54−sum13−c∗f[a,b,c+1,d,x,y]+54−sum13−d∗f[a,b,c,d+1,x,y]+
1 54 − s u m ∗ min 1 ≤ x ′ ≤ 4 f [ a , b , c , d , x ′ , y ] ( i f ( x = = 0 ) + \frac{1}{54-sum}*\min_{1\le x'\le4}{f[a,b,c,d,x',y]}(if(x==0)+ 54−sum1∗1≤x′≤4minf[a,b,c,d,x′,y](if(x==0)+
1 54 − s u m ∗ min 1 ≤ y ′ ≤ 4 f [ a , b , c , d , x , y ′ ] i f ( y = = 0 ) \frac{1}{54-sum}*\min_{1\le y'\le4}{f[a,b,c,d,x,y']}if(y==0) 54−sum1∗1≤y′≤4minf[a,b,c,d,x,y′]if(y==0)
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;
}