【题目链接】

http://poj.org/problem?id=3460

【算法】

IDA*

注意特判答案为0的情况

【代码】

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std; int i,j,n,step,T;
int a[],b[]; inline bool check()
{
int i;
for (i = ; i <= n; i++)
{
if (b[i] != i)
return false;
}
return true;
}
inline int calc()
{
int i,ret = ;
for (i = ; i <= n; i++)
{
if (b[i] != b[i-] + )
ret++;
}
return (ret - ) / + ;
}
inline bool dfs(int dep)
{
int i,j,k,l;
int tmp[];
if (dep == step)
{
if (check())
return true;
}
if (dep + calc() > step) return false;
for (i = ; i <= n - ; i++)
{
for (j = ; j <= n - i; j++)
{
for (k = i + j; k <= n + ; k++)
{
for (l = ; l <= n; l++) tmp[l] = b[l];
for (l = i + j; l < k; l++) b[i+l-i-j] = tmp[l];
for (l = k - j; l < k; l++) b[l] = tmp[l-k+i+j];
if (dfs(dep+)) return true;
for (l = ; l <= n; l++) b[l] = tmp[l];
}
}
}
return false;
} int main()
{ scanf("%d",&T);
while (T--)
{
scanf("%d",&n);
for (i = ; i <= n; i++) scanf("%d",&a[i]);
for (i = ; i <= ; i++)
{
step = i;
for (j = ; j <= n; j++) b[j] = a[j];
if (dfs())
{
printf("%d\n",step);
break;
} else step = ;
}
if (step == ) printf("5 or more\n");
} return ; }

【POJ 3460】 Booksort的更多相关文章

  1. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  2. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  3. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  4. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  5. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  6. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  7. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

  8. BZOJ2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 513  Solved: 201[Submit][ ...

  9. 【POJ 1125】Stockbroker Grapevine

    id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...

随机推荐

  1. 如何让win32 c++窗口不出现在任务栏

    把窗口作为某一个窗口的子窗口,然后设置WS_POPUP就可以了.使用CreateWindow时的第三个参数设置为WS_CHILD|WS_POPUP.

  2. MyBatis入门2_增删改查+数据库字段和实体字段不一致情况

    本文为博主辛苦总结,希望自己以后返回来看的时候理解更深刻,也希望可以起到帮助初学者的作用. 转载请注明 出自 : luogg的博客园 谢谢配合! 当数据库字段和实体bean中属性不一致时 之前数据库P ...

  3. windows环境搭建ui自动化环境

    windows环境安装python虚拟环境 https://www.cnblogs.com/suke99/p/5355894.html https://www.cnblogs.com/jiuyang/ ...

  4. php第十三节课

    查询 <?php class DBDA{ public $host = "localhost"; //数据库地址 public $uid = "root" ...

  5. time库

    简介 返回系统当前时间戳(正常的生活时间) 返回格林威治时间戳对应的struct_time对象 本地时间的struct_time对象 当前时间戳对应的易读格式字符串时间(周几,月份,号数,时,分,秒, ...

  6. map put

    public class test { static Map<String, Map<String, Integer>> mapB = new HashMap<Strin ...

  7. [USACO16OPEN]关闭农场Closing the Farm(洛谷 3144)

    题目描述 Farmer John and his cows are planning to leave town for a long vacation, and so FJ wants to tem ...

  8. CODEVS1533 Fibonacci数列 (矩阵乘法)

    嗯,,,矩阵乘法最基础的题了. Program CODEVS1250; ..,..] of longint; var T,n,mo:longint; a,b:arr; operator *(a,b:a ...

  9. py文件控制台执行时,报错:引入的模块不存在

    1.描述:该模块在IDE中是可以正确执行的.但是从cmd控制台执行时,报错:该模块引入的其他模块不存在. 2.解决:在该模块的#encoding:utf-8 之后另起一行加如下代码: #encodin ...

  10. 【ACM】hdu_2004_成绩转换_201307261516

    成绩转换Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...