题解:
递推
然后再加上概率的计算
代码:
#include<bits/stdc++.h> using namespace std; const int N=255; int T,n,r,d[N]; double p[N],f[N][N],pw[N][N]; int main() { scanf("%d",&T); while (T--) { scanf("%d%d",&n,&r); memset(f,0,sizeof(f)); for (int i=1;i<=n;i++)scanf("%lf%d",&p[i],&d[i]); double ans=0; for (int i=1;i<=n;i++) { pw[i][0]=1; for (int j=1;j<=r;j++)pw[i][j]=pw[i][j-1]*(1-p[i]); } f[0][r]=1; for (int i=0;i<n;i++) for (int j=0;j<=r;j++) { f[i+1][j]+=f[i][j]*pw[i+1][j]; if (j-1>=0) { f[i+1][j-1]+=f[i][j]*(1-pw[i+1][j]); ans+=f[i][j]*(1-pw[i+1][j])*d[i+1]; } } printf("%.10lf\n",ans); } return 0; }