神犇题解:http://blog.csdn.net/popoqqq/article/details/45365759
f[i][j]应为考虑到 i 还剩 j 个机会 这样一个局面的概率
神DP
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; int n,m; long double ans; long double p[305],d[305],f[305][305]; long double Pow(long double x,int p) { long double ret=1.0; for (;p;x*=x,p>>=1) if(p&1) ret*=x; return ret; } int main() { freopen("t.in","r",stdin); freopen("t.out","w",stdout); int Q; double a,b; scanf("%d",&Q); while (Q--) { memset(f,0,sizeof f); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { scanf("%lf%lf",&a,&b); p[i]=a,d[i]=b; } f[0][m]=1.0,ans=0.0; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { f[i][j]=f[i-1][j]*Pow(1-p[i-1],j)+f[i-1][j+1]*(1-Pow(1-p[i-1],j+1)); ans+=f[i][j]*(1-Pow(1-p[i],j))*d[i]; } printf("%.10lf\n",(double)ans); } return 0; }