- POJ 2151 - Check the difficulty of problems
- Time: 2000MS
- Memory: 65536K
- 难度: 初级
- 分类: 概率
0x00 POJ 原题
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:
All of the teams solve at least one problem.
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
Source
POJ Monthly,鲁小石
0x10 题目概述
ACM 比赛中,共 M 道题,T 个队,pij 表示第 i 队解出第 j 题的概率
问 每队至少解出一题且冠军队至少解出 N 道题的概率。
0x20 解题思路
概率+DP,概率不好真的拿不下这题
这题难点不在编程,在于问题的转化和理解
只要能用笔算出答案,离 AC 也就不远了。。。
要求:
- 每队至少解出一题 且 冠军队至少解出 N 道题的概率
- 由于冠军队可以不止一队,即允许存在并列冠军
则原来的所求的概率可以转化为:
每队均至少做一题的概率 P1 减去 每队做题数均在 1 到 N-1 之间的概率 P2

0x30 AC 源码
//Memory Time
//8272K 110MS
#include<iostream>
#include<iomanip>
using namespace std;
int M,T,N; //M:题数 T:队数 N:冠军队至少做题数
double dp[1001][31][31]; //状态方程: dp[i][j][k]为第i队PASS前j题中的k题的概率
double p[1001][31]; //p[i][j]为第i队通过第j题的概率
double s[1001][31]; //s[i][j]为第i队在M题中至少PASS j题的概率
void ProTable(void) //概率打表
{
memset(dp,0.0,sizeof(dp));
memset(s,0.0,sizeof(s));
int i,j,k;
for(i=1;i<=T;i++) //逐队枚举
{
/*Initial*/
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]);
/*Dp*/
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]);
s[i][0]=dp[i][M][0];
for(k=1;k<=M;k++)
s[i][k]=s[i][k-1]+dp[i][M][k];
}
return;
}
int main(int i,int j)
{
while(cin>>M>>T>>N)
{
if(!M && !T && !N)
break;
/*Input*/
for(i=1;i<=T;i++)
for(j=1;j<=M;j++)
cin>>p[i][j];
/*Compute the Probability*/
ProTable();
double p1=1.0;
for(i=1;i<=T;i++)
p1*=(s[i][M]-s[i][0]); //所有队至少做1题的概率
double p2=1.0;
for(i=1;i<=T;i++)
p2*=(s[i][N-1]-s[i][0]); //所有队做的题数均在1~N-1之间的概率
/*Output*/
cout<<fixed<<setprecision(3)<<p1-p2<<endl;
//每队至少解出一题 且 至少有一队(冠军队)能至少解出N道题的概率
}
return 0;
}