Permutation
Practice
3.9 (91 votes)
Algorithms
Breadth first search
Easy
Graphs
Problem
91% Success 12962 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
46 votes
Tags:
AlgorithmsApprovedBreadth First SearchDepth First SearchEasyGraphsOpen
Points:20
15 votes
Tags:
AlgorithmsBreadth First SearchGraphsLogic-Based
Points:20
29 votes
Tags:
AlgorithmsBreadth First SearchGraphsImplementationMatrix