ProblemC. The Problem Needs 3D Arrays
Description
A permutation is asequence of integers p1, p2, . . . , pn,consisting of n distinct positive integers and each of them does notexceed n. Assume that r(S) of sequence S denotes the number ofinversions in sequence S (if i < j and Si > Sj,then the pair of (i, j) is called an inversion of S), l(S) ofsequence S denotes the length of sequence S. Given a permutation P oflength n, it’s your task to find a subsequence S of P with maximumr(S) / l(S). A subsequence of P is a sequence (pi1, pi2,. . . , pit) which satisfies that 0 < i1 <i2 < . . . < it ≤ n.
Input
The first line ofthe input gives the number of test cases, T. T test cases follow.
For each test case,the first line contains an integer n (1 ≤ n ≤ 100), the length ofthe permutation P. The second line contains n integers p1,p2, . . . , pn, which represents thepermutation P.
Output
For each test case,output one line containing “Case #x: y”, where x is the test casenumber (starting from 1) and y is the maximum r(S) / l(S).
Your answer will beconsidered correct if it is within an absolute error of 10−6of the correct answer.
Samples
Sample Input |
Sample Output |
1 5 3 4 2 5 1 |