Check the difficulty of problems
Time limit:2000 ms |
|
Memory limit:65536 K |
Total submissions:3191 |
|
Accepted:1416 |
Description
Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the organizer usually failed CT 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 has CT 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 shoshould not be processed.
Output
For each test case, please output the answer in a separate line. The result shocould be 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 and Lu Xiaoshi put this question into probability DP, rather than DP. Although this question is about probability, it is different from other probability DP. This is a simple DP approach. For explanations, see the notes:
/* Poj 2151 question: In the ACM competition, there were a total of M questions and T teams, pij indicates the probability that team I solves question J. Each team should solve at least one question and the champion army should solve at least N questions. Resolution: DP sets DP [I] [J] [k] to indicate the probability that the team I solves the K-way in the previous J-way Question: DP [I] [J] [k] = DP [I] [J-1] [k-1] * P [J] [k] + dp [I] [J-1] [k] * (1-p [J] [k]); initialize DP [I] [0] [0] and DP [I] [J] [0]; if s [I] [k] indicates the probability that the question created by team I is less than or equal to K, then s [I] [k] = DP [I] [m] [0] + DP [I] [m] [1] + ''' + dp [I] [m] [k]; the probability of each team making at least one question is p1 = (1-s [1] [0]) * (1-s [2] [0]) * ''' (1-s [T] [0]); each team has one to more questions ~ The probability of N-1 is P2 = (s [1] [N-1]-s [1] [0]) * (s [2] [N-1]-s [2] [0]) * ''' (s [T] [N-1]-s [T] [0]); the final answer is P1-P2. */ # Include <Stdio. h> # Include < String . H> # Include <Algorithm> # Include <Iostream># Include <Math. h> Using Namespace STD; Double DP [ 1010 ] [ 50 ] [ 50 ]; Double S [ 1010 ] [ 50 ]; Double P [ 1010 ] [50 ]; Int Main (){ Int M, n, T; While (Scanf ( " % D " , & M, & T, & N )! = EOF ){ If (M = 0 & T = 0 & Amp; n = 0 )Break ; For ( Int I = 1 ; I <= T; I ++ ) For ( Int J = 1 ; J <= m; j ++ ) Scanf ( " % Lf " ,& P [I] [J]); For ( Int I = 1 ; I <= T; I ++ ) {DP [I] [ 0 ] [ 0 ] = 1 ; For ( Int J = 1 ; J <= m; j ++) DP [I] [J] [ 0 ] = DP [I] [J- 1 ] [ 0 ] * ( 1 - P [I] [J]); For ( Int J = 1 ; J <= m; j ++ ) For ( Int 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 ( Int K = 1 ; K <= m; k ++) s [I] [k] = s [I] [k- 1 ] + DP [I] [m] [k];} Double P1 = 1 ; Double P2 = 1 ; For ( Int I = 1 ; I <= T; I ++ ) {P1 * = ( 1 -S [I] [ 0 ]); P2 * = (S [I] [n- 1 ]-S [I] [ 0 ]);} Printf ( " %. 3lf \ n " , P1-P2 );} Return 0 ;}