2 条题解
-
0
阎帝代码
#include<bits/stdc++.h> using namespace std; const double INF=1e20,eps=1e-9; int A,B,C,D; double f[16][16][16][16][5][5]; double dp(int a,int b,int c,int d,int x,int y) { double &v=f[a][b][c][d][x][y];//为了省事^v^ if(v>eps)return v;//计算过 int as=a+(x==1)+(y==1); int bs=b+(x==2)+(y==2); int cs=c+(x==3)+(y==3); int ds=d+(x==4)+(y==4);//每种花色的数量(算大小王) if(as>=A&&bs>=B&&cs>=C&&ds>=D)return v=0;//达到目标 int Ls=54-(a+b+c+d+(x!=0)+(y!=0));//剩下的 if(Ls<=0)return v=INF; v=1.0; if(a<13)v+=(13.0-a)/Ls*dp(a+1,b,c,d,x,y);//抽中a if(b<13)v+=(13.0-b)/Ls*dp(a,b+1,c,d,x,y);//抽中b if(c<13)v+=(13.0-c)/Ls*dp(a,b,c+1,d,x,y);//抽中c if(d<13)v+=(13.0-d)/Ls*dp(a,b,c,d+1,x,y);//抽中d if(x==0)//小王 { double t=INF; for(int i=1;i<=4;i++)//变那种花色 t=min(t,1.0/Ls*dp(a,b,c,d,i,y));//最小期望值 v+=t; } if(y==0) { double t=INF; for(int i=1;i<=4;i++)//变那种花色 t=min(t,1.0/Ls*dp(a,b,c,d,x,i));//最小期望值 v+=t; } return v; } int main() { scanf("%d%d%d%d",&A,&B,&C,&D); memset(f,0,sizeof(f)); double t=dp(0,0,0,0,0,0); if(t>54)t=-1; printf("%.3lf\n",t); return 0; } -
0
#include <bits/stdc++.h> using namespace std; const double INF=1e20,eps=1e-9; int A,B,C,D; double f[16][16][16][16][5][5]; double dp(int a,int b,int c,int d,int x,int y) { double &v=f[a][b][c][d][x][y]; if(v>eps) return v; int as=a+(x==1)+(y==1); int bs=b+(x==2)+(y==2); int cs=c+(x==3)+(y==3); int ds=d+(x==4)+(y==4); if(as>=A && bs>=B && cs>=C && ds>=D ) return v=0; int Ls=54-(a+b+c+d+(x!=0)+(y!=0)); if(Ls<=0) return v=INF; v=1.0; if(a<13)v+=(13.0-a)/Ls * dp(a+1,b,c,d,x,y); if(b<13)v+=(13.0-b)/Ls * dp(a,b+1,c,d,x,y); if(c<13)v+=(13.0-c)/Ls * dp(a,b,c+1,d,x,y); if(d<13)v+=(13.0-d)/Ls * dp(a,b,c,d+1,x,y); if(x==0) { double t=INF; for(int i=1;i<=4;i++)t=min(t,1.0/Ls*dp(a,b,c,d,i,y)); v+=t; } if(y==0) { double t=INF; for(int i=1;i<=4;i++)t=min(t,1.0/Ls*dp(a,b,c,d,x,i)); v+=t; } return v; } int main() { cin>>A>>B>>C>>D; memset(f,0,sizeof(f)); double t=dp(0,0,0,0,0,0); if(t>54)t=-1; printf("%.3lf\n",t); return 0; }
- 1
信息
- ID
- 419
- 时间
- 1000ms
- 内存
- 64MiB
- 难度
- 3
- 标签
- 递交数
- 33
- 已通过
- 21
- 上传者