poj 2151

http://poj.org/problem?id=2151

Check the difficulty of problems

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 4873   Accepted: 2131

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分析:求保证每个队至少做对一题,冠军队做对n个题的概率。
保证每个队至少做对一题,冠军队做对n个题的概率=每个队至少做对一道题-没有一个队做到n到题。(每个队最多做了n-1个题),dp[i][j][k]表示第i个对做到j题,目前做对了k题。dp[i][j[k]=dp[i][j-1][k]*(1-a[i][j])+dp[i][j-1][k-1]*a[i][j];s[i][k]表示i对至少做对了k题的概率注意边界。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
double dp[1005][40][40];
int main()
{
   int m,t,n,i,j,k;
   double a[1005][40],cnt,ans,sum,s[1005][40];
   while(~scanf("%d%d%d",&m,&t,&n))
   {
       memset(dp,0,sizeof(dp));
       memset(s,0,sizeof(s));
               cnt=1;
               ans=1;
               sum=1;
       if(m==0&&t==0&&n==0)
              break;
        for(i=1;i<=t;i++)
          {
              for(j=1;j<=m;j++)
              {
                 scanf("%lf",&a[i][j]) ;
                 cnt*=(1-a[i][j]);
              }
              ans*=(1-cnt);
              cnt=1;
          }
           for(i=1;i<=t;i++)
          {
             dp[i][1][0]=1-a[i][1];
              dp[i][1][1]=a[i][1];
             for(j=2;j<=m;j++)
                 dp[i][j][0]=dp[i][j-1][0]*(1-a[i][j]);
             for(j=2;j<=m;j++)
              {
                 for(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(k=1;k<=n-1;k++)
                 s[i][n-1]+=dp[i][m][k];
             }
          for(i=1;i<=t;i++)
          {
             sum*=s[i][n-1];

          }
      printf("%.3lf\n",ans-sum);

   }
   return 0;
}

poj 2151,布布扣,bubuko.com

时间: 2024-08-05 13:41:07

poj 2151的相关文章

poj 2151 Check the difficulty of problems

dp[i][j][s]表示第i个人,在前j个问题解决了s个问题 dp[i][j][s]=dp[i][j-1][s-1]*p[i][j]+dp[i][j-1][s]*(1-p[i][j]); 1 #include<iostream> 2 #include<string> 3 #include<cstdio> 4 #include<vector> 5 #include<queue> 6 #include<stack> 7 #include

POJ 2151 Check the difficulty of problems (概率dp)

题意:给出m.t.n,接着给出t行m列,表示第i个队伍解决第j题的概率. 现在让你求:每个队伍都至少解出1题,且解出题目最多的队伍至少要解出n道题的概率是多少? 思路:求补集. 即所有队伍都解出题目的概率,减去所有队伍解出的题数在1~n-1之间的概率 这里关键是如何求出某个队伍解出的题数在1~n-1之间的概率,采用dp的方法: 用p(i,j)表示前i道题能解出j道的概率,有p(i,j)=p(i-1,j)*(1-p(i))+p(i-1,j-1)*p(i)p(i)表示解出第i题的概率. #inclu

poj 2151 概率dp

//poj 2151 概率dp 1 #include "iostream" 2 #include "cstdio" 3 #include "cstring" 4 #include "algorithm" 5 using namespace std; 6 double dp[33][33]; 7 int M, T, N; //problem, team, least 8 double p[1010][33]; 9 int mai

poj 2151 Check the difficulty of problems(线段树+概率)

Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4465   Accepted: 1966 Description Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the organizer usually exp

poj 2151 Check the difficulty of problems (dp,概率)

链接:poj 2151 题意:比赛中有M道题,T个参赛队,pij表示第i队解出第j题的概率, 求每队至少解出一题,且冠军队至少解出N道题的概率 分析:要求每队至少解出一题,且冠军队至少解出N道题的概率 则原来的所求的概率可以转化为: 每队均至少做一题的概率P1 减去 每队做题数均在1到N-1之间的概率P2 设dp[i][j][k]表示第i队在前j道题解出k道题的概率 则dp[i][j][k]=dp[i][j-1][k-1]*pij+dp[i][j-1][k]*(1-pij) 设sum[i][j]

POJ 2151 Check the difficulty of problems (动态规划-概率DP)

Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4522   Accepted: 1993 Description Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the organizer usually exp

【POJ 2151】Check the difficulty of problems

[POJ 2151]Check the difficulty of problems 明明是道概率dp 训练计划里却赤果果放在了hash+二分里....shenmegui 不过强行把概率dp给整了出来..自己瞎捣鼓居然捣鼓出来了 T支队伍每支队伍都要解M道题 问每只队伍至少解1道并且解答最多的队伍要解N道以上的概率是多少 直接做很难 可以用补集 P(AllTeam >= 1 && MaxTeam >= N) = 1 - P(HasTeam < 1 || AllTeam &

poj 2151 Check the difficulty of problems (检查问题的难度)

poj 2151 Check the difficulty of problems http://poj.org/problem?id=2151 题意:此刻有tn道题目,有dn个队伍,知道每个队伍能答对每个题目的概率,问:冠军至少答对n(1<=n<=tn)道题目,其他队伍至少要答对一道题目的概率 dp+概率 方法: f[i][j]第i队做对第j个题的概率 g[i][j][k]第i队前j个题做对k个题的概率 状态转移方程:g[i][j][k] = g[i][j-1][k-1]*f[i][j] +

POJ 2151 Check the difficulty of problems:概率dp【至少】

题目链接:http://poj.org/problem?id=2151 题意: 一次ACM比赛,有t支队伍,比赛共m道题. 第i支队伍做出第j道题的概率为p[i][j]. 问你所有队伍都至少做出一道,并且有队伍做出至少n道的概率. 题解: 关于[至少]问题的表示. 对于每一支队伍: mst[i][j] = P(第i支队伍做出至多j道题) 则 P(第i支队伍做出至少j道题) = 1 - mst[i][j-1] 对于所有队伍: P(所有队伍至少答出一题) = ∏ (1 - mst[i][0]) P(