TopCoder problem "AverageAverage" used in Member SRM 482 (Division II Level One)



Problem Statement

    

Given a int[] numList, for each non-empty subset of numList, compute the average of its elements, then return the average of those averages.

 

Definition

    
Class:AverageAverage
Method:average
Parameters:int[]
Returns:double
Method signature:double average(int[] numList)
(be sure your method is public)
    
 

Notes

-The returned value must have an absolute or relative error less than 1e-9.
 

Constraints

-

numList will contain between 1 and 8 elements, inclusive.

-

All elements of numList will be between -1000 and 1000, inclusive.

-

All elements of numList will be distinct.

 

Examples

0)
    
{1,2,3}
Returns: 2.0
The non-empty subsets of numList are: {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, and {1,2,3}, whose respective averages are: 1, 2, 3, 1.5, 2, 2.5, and 2. The average of the averages is 2.
1)
    
{42}
Returns: 42.0
There is only one non-empty subset to consider.
2)
    
{3,1,4,15,9}
Returns: 6.4

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=14235&pm=11121

Writer:

pieguy

Testers:

ivan_metelsky , boba5551 , it4.kp , abal9002

Problem categories:

Brute Force, Simple Math, Simple Search, Iteration