Check the difficulty of problems

Description

Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the organizer usually expect the contest result satisfy the following two terms: 
1. All of the teams solve at least one problem. 
2. The champion (One of those teams that solve the most problems) solves at least a certain number of problems. 

Now the organizer has studied out the contest problems, and through the result of preliminary contest, the organizer can estimate the probability that a certain team can successfully solve a certain problem. 

Given the number of contest problems M, the number of teams T, and the number of problems N that the organizer expect the champion solve at least. We also assume that team i solves problem j with the probability Pij (1 <= i <= T, 1<= j <= M). Well, can you calculate the probability that all of the teams solve at least one problem, and at the same time the champion team solves at least N problems? 

Input

The input consists of several test cases. The first line of each test case contains three integers M (0 < M <= 30), T (1 < T <= 1000) and N (0 < N <= M). Each of the following T lines contains M floating-point numbers in the range of [0,1]. In these T lines, the j-th number in the i-th line is just Pij. A test case of M = T = N = 0 indicates the end of input, and should not be processed.

Output

For each test case, please output the answer in a separate line. The result should be rounded to three digits after the decimal point.

Sample Input

2 2 2
0.9 0.9
1 0.9
0 0 0

Sample Output

0.972


#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
double dp[1010][50][50];
double a[1010][50];
double s[1010][50];
int main(){
	int n,m,t;//n人数m题目数t至少得题数 
	while(scanf("%d %d %d",&m,&n,&t)!=EOF){
		if(m==0 && t==0 && n==0) 
			return 0;
		memset(dp,0,sizeof(dp));
		memset(s,0,sizeof(s));
		memset(a,0,sizeof(a));
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++)
				scanf("%lf",&a[i][j]);
		}
		for(int i=1;i<=n;i++){
			dp[i][0][0]=1.0;
			for(int j=1;j<=m;j++){
				dp[i][j][0]=dp[i][j-1][0]*(1-a[i][j]);
			}
		}
		
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				for(int k=1;k<=j;k++)
					dp[i][j][k]=dp[i][j-1][k]*(1-a[i][j])+dp[i][j-1][k-1]*a[i][j];
			}
		}
		for(int i=1;i<=n;i++){
			for(int j=0;j<=m;j++){
				if(j!=0)
					s[i][j]=s[i][j-1]+dp[i][m][j];
				else
					s[i][j]=dp[i][m][0];
			}
		}
		
		double p1=1.0,p2=1.0;	
		if(t==1) 
			p2=0;
		for(int i=1;i<=n;i++){
			p1*=(1-s[i][0]);
			p2*=(s[i][t-1]-s[i][0]);
		}
		printf("%.3lf\n",p1-p2);
	}
}

猜你喜欢

转载自blog.csdn.net/doublekillyeye/article/details/81006382