Crusher`s Code
Wesley Crusher is the teaching assistant for Introduction to Algorithms. During his first class, the cadets were asked to come up with their own sorting algorithms. Monty came up with the following code:
Carlos, inspired, came up with the following code:
Wesley needs to determine which algorithm is better.
For a given input array of up to 8 values, calculate and print the expected number of iterations for each algorithm. That is, on average, how many iterations should each algorithm take for the given input?
Input
The first line contains the number of test cases t (2 ≤ t ≤ 100). Each test case is given on a single line. The first value is the number of array elements n (2 ≤ n ≤ 8). This is followed on the same line by n integer array elements. The array elements will have values between 0 and 100 inclusive. The array elements may not be distinct.
Output
For each test case, print out the expected number of iterations for Monty's algorithm and for Carlos's algorithm, as shown in the sample output section. There should be exactly one space between words and no spaces at the start of each line or at the end of each line. There should be exactly six digits after the decimal point. Rounding should be to nearest representable value.