poj 2151 Check the difficulty of problems 概率DP
简单的概率DP!!!
结果=所以的情况-所以满足且<=n-1的情况!
代码如下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<iostream> 2 #include<stdio.h> 3 #include<algorithm> 4 #include<iomanip> 5 #include<cmath> 6 #include<cstring> 7 #include<vector> 8 #define ll __int64 9 #define pi acos(-1.0) 10 #define MAX 1001 11 using namespace std; 12 double p[MAX][32],dp[50][32],s[MAX][32],p1,p2; 13 int main(){ 14 int n,m,t,i,j,k; 15 while(cin>>m>>t>>n){ 16 if(m==0&&t==0&&n==0) break; 17 for(i=1;i<=t;i++) 18 for(j=1;j<=m;j++) 19 cin>>p[i][j]; 20 for(i=1;i<=t;i++){ 21 dp[0][0]=1; 22 for(j=1;j<=m;j++) dp[j][0]=dp[j-1][0]*(1-p[i][j]); 23 for(j=1;j<=m;j++) 24 for(k=1;k<=j;k++){ 25 dp[j][k]=dp[j-1][k-1]*p[i][j]+dp[j-1][k]*(1-p[i][j]); 26 } 27 s[i][0]=dp[m][0]; 28 for(j=1;j<=m;j++) s[i][j]=s[i][j-1]+dp[m][j]; 29 } 30 p1=p2=1; 31 for(i=1;i<=t;i++){ 32 p1*=(1-s[i][0]); 33 p2*=(s[i][n-1]-s[i][0]); 34 } 35 printf("%.3lf\n",p1-p2); 36 } 37 return 0; 38 }