Check the difficulty of problems
Time Limit: 2000MS | Memory Limit: 65536KB | 64bit IO Format: %I64d & %I64u |
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?
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题的 概率,
这个就要用到DP了nk[k][i][j]表示k个人前i题做出了j题的概率,
那么状态转移方程就是
nk[k][i][j]=nk[k][i-1][j]*(1-p[k][i])+nk[k][i-1][j-1]*p[k][i];
p[k][i]为第k个人做出了第i题的概率
*/
Problem: A | User: sdau_09_zys | |
Memory: 13112 KB | Time: 79 MS | |
Language: C++ | Result: Accepted | |
Public: |
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int MA=1010;
double p[MA][40];//第i个队伍做出j题的概率
double k[MA][40][40];//第i个队伍前j个做出o个的概率
double zhi[MA];//每个队伍至少一个题的概率
double guan[MA];
int main(){
int m,t,n;
while(cin>>m>>t>>n){
if(m==0&&t==0&&n==0)break;
for(int i=1;i<=t;i++)
{
for(int j=1;j<=m;j++){
cin>>p[i][j];
}
}
for(int i=1;i<=t;i++){
zhi[i]=1;
for(int j=1;j<=m;j++){
zhi[i]=zhi[i]*(1-p[i][j]);
}
zhi[i]=1-zhi[i];//每个队伍至少做出一个题的概率
}
for(int i=1;i<=t;i++){
k[i][0][0]=1;
for(int j=1;j<=m;j++){
k[i][j][0]=k[i][j-1][0]*(1-p[i][j]);//第i个队伍前j题做对0道
}
}
for(int i=1;i<=t;i++){
for(int j=1;j<=m;j++){
for(int o=1;o<=m;o++){
k[i][j][o]=k[i][j-1][o]*(1-p[i][j])+k[i][j-1][o-1]*p[i][j];
}
}
}
double a=0;
for(int i=1;i<=t;i++){
guan[i]=0;
for(int j=n;j<=m;j++){
guan[i]=guan[i]+k[i][m][j];
}
if(fabs(zhi[i])>0.00001){
guan[i]=guan[i]/zhi[i];
}
else
guan[i]=0;//每个队做出N题以上概率
}
double ans=1;
double ans1=1;
for(int i=1;i<=t;i++){
ans=ans*(1-guan[i]);
ans1=ans1*zhi[i];
}
ans=(1-ans)*ans1;
printf("%.3lf\n",ans);
}
return 0;
}