Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Language: Reverse
Description You will be given a list of n integers S = {1, 2, ... , (n-1), n}, please write a program to calculate the minimum number of instructions required to change the list in descending order {n, (n-1), ..., 1}. Let S[i] denote the i-th element of S, 1 ≤ i ≤ n. Each instruction takes a successive subsequence and removes that subsequence from the list, then insert that subsequence into any position of the list as a parameter. Each instruction can be represented by three numbers (pos1,length,pos2),which means we will remove subsequence S[pos1] ..... S[pos1+length-1], then insert them after the S[pos2] (pos2=0 will insert it at the beginning). We always have: 1 ≤ pos1 ≤ n, 1 ≤ length ≤ n+1-pos1, 0 ≤ pos2 ≤ n-length For example: Input The input contains one integer n. 1 ≤ n ≤ 100 Output The first line of output contains one integer C denoting the number of instructions. Sample Input Sample Input 1 3 Sample Input 2 4 Sample Output Sample Output 1 2 1 1 2 1 1 1 Sample Output 2 3 1 2 2 1 1 1 3 1 3 Source POJ Founder Monthly Contest – 2008.10.05, Lou Tiancheng |
[Submit] [Go Back] [Status] [Discuss]
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator