【题目链接】

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. SYN(synchronous)TCP/IP

    SYN(synchronous)是TCP/IP建立连接时使用的握手信号.在客户机和服务器之间建立正常的TCP网络连接时,客户机首先发出一个SYN消息,服务器使用SYN+ACK应答表示接收到了这个消息, ...

  2. PHP 之微信JSSDK类封装

    <?php class JSSDK { private $appId; private $appSecret; public function __construct($appId, $appS ...

  3. 《C++ Primer 第5版》第1章

    1.1 一个简单的C++程序 #include <iostream>int main() {    std::cout << "Hello World!" ...

  4. 27.7 并行语言集成查询(PLinq)

    static void Main() { ObsoleteMethods(Assembly.Load("mscorlib.dll")); Console.ReadKey(); } ...

  5. cmake编译安装mysql

    运维开发技术交流群欢迎大家加入一起学习(QQ:722381733) 前言:这里我使用的安装方式是(cmake编译),我选择的版本是:cmake-2.8.8.tar.gz.mysql-5.5.32.ta ...

  6. net core 配置Redis Cache

    参考文章地址:https://dotnetcoretutorials.com/2017/01/06/using-redis-cache-net-core/ 具体步骤: 1   Install-Pack ...

  7. 分布式服务框架Dubbo入门案例和项目源码

    本项目源代码:http://download.csdn.net/detail/fansunion/9498406 Dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案, 是 ...

  8. hdu2001 计算两点间的距离【C++】

    计算两点间的距离 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  9. Navicat premium连接Oracle报ORA-12514错误

    1:ORA-12514 原因:Service Name/SID中的值填的有问题,默认的是ORCL,这个值如果在安装Oracle的时候填的不是ORCL,那就会出现这个错误 解决方法:找到Oracle安装 ...

  10. jQuery学习----简单介绍,基本使用,操作样式,动画

    jQuery简单介绍 jq是js的插件库,说白了,jq就是一个js文件 凡事能用jq实现的,js都能实现.但是js能实现的,jq不一定能够实现 jq的引入 http://www.bootcdn.cn ...