扑克牌[CH3803]

题面描述

传送门

思路

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]+ 54sum13af[a+1,b,c,d,x,y]+54sum13bf[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]+ 54sum13cf[a,b,c+1,d,x,y]+54sum13df[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)+ 54sum11x4minf[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) 54sum11y4minf[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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值