【以后再做再总结】【IDA*】【Jason's_ACM_解题报告】Editing a Book

Editing a Book

You have n equal-length paragraphs numbered 1 to n. Now you want to arrange them in the order of 1, 2, ..., n. With the help of a clipboard, you can easily do this: Ctrl-X (cut) and Ctrl-V (paste) several times. You cannot cut twice before pasting, but you can cut several contiguous paragraphs at the same time - they'll be pasted in order.


For example, in order to make {2, 4, 1, 5, 3, 6}, you can cut 1 and paste before 2, then cut 3 and paste before 4. As another example, one copy and paste is enough for {3, 4, 5, 1, 2}. There are two ways to do so: cut {3, 4, 5} and paste after {1, 2}, or cut {1, 2} and paste before {3, 4, 5}.


Input
The input consists of at most 20 test cases. Each case begins with a line containing a single integer n (1 < n < 10), the number of paragraphs. The next line contains a permutation of 1, 2, 3,..., n. The last case is followed by a single zero, which should not be processed.


Output
For each test case, print the case number and the minimal number of cut/paste operations.


Sample Input
6
2 4 1 5 3 6
5
3 4 5 1 2
0


Sample Output
Case 1: 2
Case 2: 1





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值