Live2d Test Env

POJ2151Check the difficulty of problems (概率DP)

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

题意:

一套题,有T个题,M个人应考,已知每个人做来某题的概率。问X的概率。X满足,每个考生至少做来一道题。至少有一人做的题不少于N道。

思路:

不算是很典型的概率DP,更像是一道简单数学题。

可以把所有考生都至少做来一道题的概率减去 每个人都做来1到n-1道题的概率。

p=[(1-x11)*(1-x12)(..) ] * [(1-x21)*(1-x22)(..)]*[...]     -    [...]*[...] ,这样的话,用组合数就ok了。

但是这里是用的DP是思路,先把考生与考题的关系求出来,p[i][j][k] 表示第i个考试前j个题会做k道的概率。再根据题意进行DP。

 

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
using namespace std;
double p[1010][32][32],P1,P2,a[1010][32],tmp,res;
int main()
{
    int i,j,k,m,n,t;
    while(~scanf("%d%d%d",&m,&t,&n)){//t人 m题 
        if(m==0&&t==0&&n==0) return 0;
        memset(p,0,sizeof(p));
        for(i=1;i<=t;i++)
         for(j=1;j<=m;j++)
           scanf("%lf",&a[i][j]);
        for(i=1;i<=t;i++)
         for(j=0;j<=m;j++)
          for(k=0;k<=j;k++){
               if(j==0&&k==0) p[i][j][k]=1;
               else if(j==k)  p[i][j][k]=p[i][j-1][k-1]*a[i][j];
               else if(k==0)  p[i][j][k]=p[i][j-1][k]*(1-a[i][j]);
               else p[i][j][k]=p[i][j-1][k-1]*a[i][j]+p[i][j-1][k]*(1-a[i][j]);
          }
        res=1;P1=1;
        for(i=1;i<=t;i++){
            P1*=(1-p[i][m][0]);
            tmp=0;
            for(j=1;j<n;j++) tmp+=p[i][m][j]; 
            res*=tmp;    
        }
        res=P1-res;
        printf("%.3f\n",res); //lf就出错,poj经常这样 
    }  return 0;
}

 

posted @ 2017-12-26 16:39  nimphy  阅读(382)  评论(0编辑  收藏  举报