http://poj.org/problem?id=2151
看的题解。。表示没看懂状态转移方程。。
#include<stdio.h> #include<string.h> int m,t,n; double dp[1002][32][32],p[1002][32],tt[1002][32]; int main() { int i,j,k; while(~scanf("%d%d%d",&m,&t,&n)) { if (!m && !t && !n) break; memset(dp,0.0,sizeof(dp)); memset(tt,0.0,sizeof(tt)); for (i = 1; i <= t; i ++) for (j = 1; j <= m; j ++) { scanf("%lf",&p[i][j]); } for (i = 1; i <= t; i ++) { dp[i][0][0] = 1.0; for (j = 1; j <= m; j ++) { dp[i][j][0] = dp[i][j-1][0]*(1-p[i][j]); } for (j = 1; j <= m; j ++) { for (k = 1; k <= j; k ++) { dp[i][j][k] = dp[i][j-1][k-1]*p[i][j] + dp[i][j-1][k]*(1-p[i][j]); } } tt[i][0] = dp[i][m][0]; for (k = 1; k <= m; k ++) { tt[i][k] = tt[i][k-1] + dp[i][m][k]; } } double p1 = 1.0,p2=1.0; for (i = 1; i <= t; i ++) { p1 *= (tt[i][m]-tt[i][0]); p2 *= (tt[i][n-1]-tt[i][0]); } printf("%.3f ",p1-p2); } return 0 ; }