Given a permutation of , you must sort it in increasing order. The only operation allowed is to reverse the first elements of the current permutation, for any .
For instance, in one step we can transform [3, 5, 2, 4, 1] into [5, 3, 2, 4, 1], [2, 5, 3, 4, 1], [4, 2, 5, 3, 1] and [1, 4, 2, 5, 3].
Given a permutation, what is the minimum number of steps to sort it?
Input consists of several permutations, each with an between 1 and 18, followed by different numbers between 1 and .
For every permutation, print the minimum number of operations to sort it.
Author: Josep Grané
Generation: 2026-01-25T11:58:23.267Z
© Jutge.org, 2006–2026.
https://jutge.org