Permutation
Practice
3.9 (91 votes)
Algorithms
Breadth first search
Easy
Graphs
Problem
91% Success 12960 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Given a permutation of 1 to n, you need to perform some operations to make it into increasing order. Each operation is to reverse an interval \(a_1,a_2,\dots,a_x(1\le x\le n)\) (a prefix). Your goal is to minimize the number of operations.

Input

The first line contains an integer \(n\) (\(1\le n\le 8\)).

The second line contains \(n\) space separated integers, representing the sequence \(a\).

Output

An integer representing the answer, that is, the minimum number of operations needed to make the permutation into increasing order.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
7 votes
Tags:
Breadth-first searchGraphsAlgorithms
Points:20
153 votes
Tags:
AlgorithmsApprovedBreadth First SearchEasyGraphsGreedy AlgorithmsMathOpen
Points:20
74 votes
Tags:
AlgorithmsBreadth First SearchEasyGraphs