Title Link: POJ 2151 Check The difficulty of problems
Surface:
Check the difficulty of problems
| Time Limit: 2000MS |
|
Memory Limit: 65536K |
| Total Submissions: 5519 |
|
Accepted: 2431 |
Description
Organizing a programming contest is a easy job. To avoid making the problems too difficult, the organizer usually expect the contest result satisfy the following S
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 have studied out the contest problems, and through the result of preliminary contest, the organizer can E Stimate 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-calculate the probability, all of the teams solve at least one problem, and at the same time the Champio N team solves at least n problems?
Input
The input consists of several test cases. The first line of all test case contains three integers m (0 < M <=), T (1 < T <=) and N (0 < N &L T;= 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 is processed.
Output
For each test case, please output the answer-a separate line. The result should is rounded to three digits after the decimal point.
Sample Input
2 2 20.9 0.91 0.90 0 0
Sample Output
0.972
Source
POJ Monthly, Lu Xiao
First write probability DP, feel and DP somewhat different, draw on this blog: Kinghai
Code:
#include <iostream> #include <cstdio> #include <cstring>using namespace std;double correspond[1005][ ];d ouble dp[1005][31][31];int main () {int n,m,t;double ans=1,tmp,sum;while (scanf ("%d%d%d", &m,&t,&n) && (m| | t| | N) {ans=tmp=1;for (int i=0;i<t;i++) {for (int j=1;j<=m;j++) scanf ("%lf", &correspond[i][j]);} Memset (Dp,0,sizeof (DP)); DP[I][J][K] The first team, do the first J question, do the probability for the k question for (int i=0;i<t;i++) {dp[i][0][0]=1; for (int j=1;j<=m;j++) {//or 0-way, that is the current one did not do to dp[i][j][0] = dp[i][j-1][0] * (1-corr ESPOND[I][J]); for (int k =1; k <= J; k++)//Do the right k, either right before the K-way, this time not right, or before the K-1 road, this time dp[i][j][k] = dp[i][ J-1][K-1] * correspond[i][j]+ dp[i][j-1][k] * (1-correspond[i][j]); }}//exclude any one person from doing the right thing together. for (int i=0;i<t;i++) ans *= (1-dp[i][m][0]); The exclusion of all is done only for the 1~n-1 situation for (int i=0;i<t;i++) {sum=0; for (int j=1;j<n;j++) SUM+=DP[I][M][J]; Tmp*=sum; } ans-=tmp; printf ("%.3f\n", ans);} return 0;}
POJ 2151 Check The difficulty of problems