eolymp
bolt
Try our new interface for solving problems
Problems

Random Shuffle

Random Shuffle

A random shuffle function is described in the pseudocode below: \textbf{n} = length of array \textbf{A} For \textbf{i} = \textbf{1} to \textbf{n} Generate a uniform random integer \textbf{r} between \textbf{1} and \textbf{n} inclusive Swap \textbf{A}\[\textbf{i}\] and \textbf{A}\[\textbf{r}\] Find the probability that the given array was produced by performing the shuffle function on the integer array \{\textbf{1}, \textbf{2}, \textbf{3}, ..., \textbf{n}\}, where \textbf{n} is the number of elements in array. \InputFile Each line is a sepate test case that contain the integer \textbf{n} (\textbf{1} ≤ \textbf{n} ≤ \textbf{10}) and the elements of array \textbf{А} - the permutation of numbers from \textbf{1} to \textbf{n}. \OutputFile For each test case print in a separate line with \textbf{8} digits after the decimal point the probabilty that the given array was produced by performing the shuffle function on the integer array \{\textbf{1}, \textbf{2}, \textbf{3}, ..., \textbf{n}\}.
Time limit 6 seconds
Memory limit 64 MiB
Input example #1
1 1
2 1 2
5 4 2 5 1 3
Output example #1
1.00000000
0.50000000
0.00672000