#include<iostream> #include<vector> #include<ctime> #include<algorithm> #include<cstdio> using namespace std; int n, maxd; int wrongn(int *p, int a, int b) { int t = 0; for (int i = a; i < b; i++) { if (p[i + 1] - p[i] != 1) t++; } return t; } bool dfs(int h, int act, int *perm) { int i, j, st, ed, k, a, b, temp[12]; /*if (!wrongn(perm, st, ed )) if (perm[st] - 1 == perm[perm[st] - 1] || perm[ed] + 1 == perm[perm[ed] + 1]) return 0;//不拆分连续数字 */ if (act--) { temp[0] = temp[n + 1] = 0; for (st = 1; st <= n; st++) for (ed = st + 1; ed <= n + 1; ed++) { for (k = 1; k <= n + 1; k++) { if (k > ed) { j = 1; for (i = 1; i < st; i++) temp[j++] = perm[i]; for (i = ed; i<k; i++) temp[j++] = perm[i]; for (i = st; i < ed; i++) temp[j++] = perm[i]; for (i = k; i <= n; i++) temp[j++] = perm[i]; } else if (k < st) { j = 1; for (i = 1; i < k; i++) temp[j++] = perm[i]; for (i = st; i < ed; i++) temp[j++] = perm[i]; for (i = k; i<st; i++) temp[j++] = perm[i]; for (i = ed; i <= n; i++) temp[j++] = perm[i]; } else continue; a = wrongn(temp, 1, n); if (!a) return true; if (a > h) continue; if (a > 3 * act) continue; if (dfs(a, act, temp)) { //cout << i << ' ' << i + j << "->" << k << endl; return true; } } } } return 0; } void solve(int T) { int i, j, k, h, ss; int perm[12]; perm[0]; for (i = 1; i <= n; i++) scanf("%d", &perm[i]); perm[0] = perm[n + 1] = 0; h = wrongn(perm, 1, n); if (!h) { printf("Case %d: 0\n", T); return; } for (maxd = 1; ; maxd++) { if (h > 3 * maxd) continue; if (dfs(h, maxd, perm)) { printf("Case %d: %d\n", T, maxd); return; } } } int main() { int T = 0; //clock_t start, stop; //start = clock(); while (scanf("%d", &n) == 1 && n) { solve(++T); } //stop = clock(); //printf("Use Time:%ld\n", (double)(stop - start)); return 0; } //system("pause"); /* 2 2 1 6 2 4 1 5 3 6 5 3 4 5 1 2 9 9 8 7 6 5 4 3 2 1 0 */
相关推荐
Adobe Audition CC Classroom in a Book (2nd Edition) By 作者: Adobe Creative Team – Maxim Jago ISBN-10 书号: 0135228328 ISBN-13 书号: 9780135228326 Edition 版本: 2 出版日期: 2018-11-17 pages 页数: ...
Adobe After Effects CC Classroom in a Book (2019 Release Finelybook 出版日期) By 作者: Lisa Fridsma – Brie Gyncild ISBN-10 书号: 0135298644 ISBN-13 书号: 9780135298640 Edition 版本: 1 出版日期: 2018-...
and a companion CD with all of the book's project files make learning a breeze as the Adobe Creative Team takes you on a self-paced tour of the image-editing powerhouse. This bestselling guide has ...
This book is a new media mini-book covering concepts central to digital audio editing using the Audacity 2.1.1 open source software package which also apply to all of the professional audio editing ...
A unique compact book on digital video editing fundamentalsCovers digital video file formats and data footprint optimizationTeaches you how to build a production pipeline,解压密码 share.weimo.info
Photo Editing Extension Demo, 苹果官方例子。 配合博客学习使用
the craft of text editing 一本电子书。放在这里收藏。
Maurilio and Narbik each did a nice job tech editing the book and finding the technical errors that can creep into a manuscript. On his third time with editing this book, Maurilio did his usual ...
The Craft of Text Editing
Samsung Editing Assets2.2.82.5.apk
Poisson_Image_Editing,泊松融合的matlab代码
The Eclipse Graphical Editing FrameWork 本资料共包含以下附件: The Eclipse Graphical Editing FrameWork.pdf
PISE Person Image Synthesis and Editing With Decoupled GAN
介绍 Eclipse Graphical Editing Framework (GEF)插件开发.
evil-cleverparens, editing语言的Evil正常状态 minor 正在进行中,工作 邪恶 cleverparensevil-cleverparens 为编辑Lisp而优化的模式编辑。 它的工作原理如下:如果有用的话,可以以防止将括号和它的他分隔符的顺序...
poisson image editing
Poisson Image Editing-2003的源代码,有VS2003, VS2005,VS2008三个版本,05的已经编译后能够直接运行,其他没有测试,对做相关研究的同学应该有帮助。
该ppt适合午间分享,适合学习影视剪辑的初学者,画面超美,有配套的剪辑视频,可以播放,分享时间大概在15-20分钟。
matlab开发-Poissonimageediting。possion图像编辑的matlab实现(无缝克隆和混合梯度)
A large percentage of time behind the computer screen is spent on editing text. Investing a little time in learning more efficient ways to use a text editor pays itself back fairly quickly. This ...