boj 12825 Next Permutation


boj 12825 Next Permutation

Permutations are intensively studied in mathematics and computer science. Pattern avoiding permutations are of special interest. A permutation p1, p2, . . . , pn of the natural numbers 1, . . . , n is called 3-1-2 pattern avoiding if there are no three indices 1 ≤ i < j < k ≤ n such that pi > pj , pi > pk and pj < pk.Write a program that computes for a given 3-1-2 pattern avoiding permutation the next 3-1-2 pattern avoiding permutation according to the lexicographic ordering.입력The first line of the input contains one integer n (3 ≤ n ≤ 10000). The second line contains n po..........



원문링크 : boj 12825 Next Permutation