F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Harmony

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 222    Accepted Submission(s): 32
Special Judge


Problem Description
Ali is given an array, which is a permutation of {1, 2, 3 ... , n}. He thinks that only the increasing sequence is harmony, so he wants to change the sequence into a harmony one. But the only operation he can use is: Choosing a contiguous subsequence {A[i], A[i + 1]...A[j]} and do a random shuffling on it. (Random shuffle means that every permutation will appear with equal possibility)
So, what¡¯s the expected number of operations when using the best strategy?
 

Input
The input consists several testcases.
First line, an integer N (0 < N <= 50) denoting the length of this array.
In the next line there are N integers, representing a permutation.
 

Output
Print one line with the expectation.
The result should be given with absolute or relative error of at most 10-6.
 

Sample Input
5 2 1 3 5 4
 

Sample Output
4.0000000000
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 06:59:51, Gzip enabled