标签:
#include<cstdio> #include<cstdlib> #include<algorithm> #include<cmath> #include<cstring> using namespace std; int dt,tj,i,n,m,j; double ans; struct card{ double p,d; }a[231]; double d[231],f[231][231],p[231][231]; int main() { scanf("%d",&dt); for(tj=1;tj<=dt;tj++){ scanf("%d%d",&n,&m); for(i=1;i<=n;i++)scanf("%lf%lf",&a[i].p,&a[i].d); memset(f,0,sizeof(f)); memset(d,0,sizeof(d)); f[m][0]=1; for(i=1;i<=n;i++)p[i][1]=1-a[i].p; for(i=2;i<=m;i++) for(j=1;j<=n;j++)p[j][i]=p[j][i-1]*(1-a[j].p); for(i=m;i>=1;i--){ for(j=0;j<n;j++){ f[i][j+1]+=f[i][j]*p[j+1][i]; f[i-1][j+1]+=f[i][j]*(1-p[j+1][i]); d[j+1]+=f[i][j]*(1-p[j+1][i]); } } ans=0; for(i=1;i<=n;i++)ans+=a[i].d*d[i]; printf("%.11lf\n",ans); } }
标签:
原文地址:http://www.cnblogs.com/applejxt/p/4450533.html