解析:
设dp[c][d][h][s][i][j]为有c,d,h,s个对应的牌,i、j记录大小王的状态。
记忆化搜索一下就ok
[code]:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int C,D,H,S,cnt[5];
double dp[15][15][15][15][5][5];
void init(){
int c,d,h,s,i,j;
for(c = 0;c < 14;c++)
for(d = 0;d < 14;d++)
for(h = 0;h < 14;h++)
for(s = 0;s < 14;s++)
for(i = 0;i < 5;i++)
for(j = 0;j < 5;j++)
dp[c][d][h][s][i][j] = -1;
}
double dfs(int c,int d,int h,int s,int i,int j){
if(c > 13||d > 13||h > 13||s > 13) return 0;
//printf("status: %d %d %d %d %d %d\n",c,d,h,s,i,j);
cnt[1] = c;
cnt[2] = d;
cnt[3] = h;
cnt[4] = s;
if(i) cnt[i]++;
if(j) cnt[j]++;
if(cnt[1]>=C&&cnt[2]>=D&&cnt[3]>=H&&cnt[4]>=S) return dp[c][d][h][s][i][j] = 0;
if(dp[c][d][h][s][i][j] > -0.5) return dp[c][d][h][s][i][j];
int k,num = cnt[1]+cnt[2]+cnt[3]+cnt[4];
double ans = 0,tmp;
num = 54 - num;
if(num == 0) return 0;
if(!i){
tmp = 100;
for(k = 1;k <= 4;k++){
tmp = min(tmp,dfs(c,d,h,s,k,j));
}
ans += tmp;
}
if(!j){
tmp = 100;
for(k = 1;k <= 4;k++){
tmp = min(tmp,dfs(c,d,h,s,i,k));
}
ans += tmp;
}
ans += (13-c)*dfs(c+1,d,h,s,i,j) + (13-d)*dfs(c,d+1,h,s,i,j)
+ (13-h)*dfs(c,d,h+1,s,i,j) + (13-s)*dfs(c,d,h,s+1,i,j);
ans = ans/num+1;
return dp[c][d][h][s][i][j] = ans;
}
int main(){
int i,j,cas;
scanf("%d",&cas);
for(int T=1;T<=cas;T++){
scanf("%d%d%d%d",&C,&D,&H,&S);
init();
printf("Case %d: ",T);
int x = (C > 13? C - 13 : 0) + (D > 13? D - 13 : 0) + (H > 13? H - 13 : 0) + (S > 13? S - 13 : 0);
if(x > 2) puts("-1");
else{
printf("%.10f\n",dfs(0,0,0,0,0,0));
}
}
return 0;
}