TopCoder problem "TheFansAndMeetingsDivOne" used in SRM 460 (Division I Level Two)



Problem Statement

    

John and Brus have become very famous people all over the world, especially in Bolivia. Stories written about them by a Bolivian man have become very popular in that country. John and Brus have decided to visit their fans in Bolivia, but unfortunately, they only have time to visit k cities each.

John will randomly choose k distinct cities. Each set of k cities has the same probability of being chosen. If he chooses the i-th city, he will meet between minJ[i] and maxJ[i] fans there, inclusive. Each possible number of fans is equally likely. Brus will go through the exact same process, but in his case, the number of fans he would meet in the i-th city is between minB[i] and maxB[i], inclusive. Return the probability that John and Brus will each meet the same total number of fans.

 

Definition

    
Class:TheFansAndMeetingsDivOne
Method:find
Parameters:int[], int[], int[], int[], int
Returns:double
Method signature:double find(int[] minJ, int[] maxJ, int[] minB, int[] maxB, int k)
(be sure your method is public)
    
 

Notes

-The returned value must be accurate to within a relative or absolute value of 1E-9.
 

Constraints

-minJ will contain between 1 and 40 elements, inclusive.
-minJ, maxJ, minB and maxB will contain the same number of elements.
-Each element of minJ, maxJ, minB and maxB will be between 1 and 40, inclusive.
-The i-th element of minJ will be less than or equal to the i-th element of maxJ.
-The i-th element of minB will be less than or equal to the i-th element of maxB.
-k will be between 1 and the number of elements in minJ, inclusive.
 

Examples

0)
    
{1}
{9}
{5}
{5}
1
Returns: 0.1111111111111111
Brus will definitely meet five fans, and the probability of John meeting five fans as well is 1/9.
1)
    
{5, 2, 5, 1, 1, 2, 4, 1}
{7, 6, 7, 3, 4, 3, 5, 1}
{8, 9, 7, 11, 12, 7, 8, 40}
{9, 10, 9, 33, 14, 7, 11, 40}
2
Returns: 4.724111866969009E-5
The only possible same total number of fans that John and Brus can meet is 14. In order for them to meet 14 fans, John must visit cities 0 and 2 and Brus must visit cities 2 and 5. In each of these cities they must meet exactly 7 fans.
2)
    
{4, 7, 4}
{7, 7, 7}
{40, 40, 40}
{40, 40, 40}
1
Returns: 0.0
No chance to meet the same number of fans.
3)
    
{3, 6, 2, 1, 1, 10, 3}
{6, 9, 5, 6, 5, 10, 9}
{1, 1, 1, 1, 8, 3, 1}
{3, 9, 7, 3, 10, 6, 5}
4
Returns: 0.047082056525158976

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=10771

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=14146&pm=10771

Writer:

Vasyl[alphacom]

Testers:

PabloGilberto , connect4 , ivan_metelsky

Problem categories:

Dynamic Programming, Simple Math