Problem
A reversal of a permutation creates a new permutation by inverting some interval of the permutation; , , and are all reversals of . The reversal distance between two permutations and , written , is the minimum number of reversals required to transform into (this assumes that and have the same length).
Given: A collection of at most 5 pairs of permutations, all of which have length 10.
Return: The reversal distance between each permutation pair.
排列的逆转通过反转排列的间隔来创建新的排列;,和 都是的冲销。的反转距离两个置换之间 和,写入,是转变需要逆转的最小数目为(假定和具有相同的长度)。
给定:最多5对排列的集合,所有排列的长度均为10。
返回值:每个排列对之间的反转距离。
Sample Dataset
1 2 3 4 5 6 7 8 9 10 3 1 5 2 7 4 9 6 10 8 3 10 8 2 5 4 7 1 6 9 5 2 3 1 7 4 10 8 6 9 8 6 7 9 4 1 3 10 2 5 8 2 7 6 9 1 5 3 10 4 3 9 10 4 1 8 6 7 5 2 2 9 8 5 1 7 3 4 6 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10
Sample Output
9 4 5 7 0