【POJ 3460】 Booksort
【题目链接】
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的更多相关文章
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
- BZOJ2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 513 Solved: 201[Submit][ ...
- 【POJ 1125】Stockbroker Grapevine
id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...
随机推荐
- UVM基础之----uvm_object
uvm_void The uvm_void class is the base class for all UVM classes. uvm_object: The uvm_object class ...
- React-Native WebView动态加载字体
背景 使用react-native构建的iOS/Android双端APP,通过WebView加载本地页面,需要根据服务器提供的字体列表实现下载和动态加载. 本地字体检查 有些字体手机操作系统已经提供了 ...
- C# 扩展类的内置方法
public class A//先定义A类 { } public static class Extension//必须先声明一个静态类,类名随意 { public static int ToInt32 ...
- Python-暑期实训day 1
python基础: 一 编程语言 什么是编程语言? 上面提及的能够被计算机所识别的表达方式即编程语言,语言是沟通的介质,而编程语言是程序员与计算机沟通的介质.在编程的世界里,计算机更像是人的奴隶,人类 ...
- 码书:编码与解码的战争 PDF 下载
码书:编码与解码的战争 PDF 下载 下载地址:https://pan.baidu.com/s/14Y_krHh-unOv4g2KYFFDgQ 如需分享码:[打开微信]->[扫描右侧二维码]-& ...
- shell使用eval进行赋值bc计算,bad substitution
开始我认为是这样的: [root@jiangyi02.sqa.zmf /home/ahao.mah/ALIOS_TEST] #cat bbb.sh #!/bin/sh eval $1_new=123 ...
- 通过git向github提交项目
按顺序学习 https://www.cnblogs.com/forget406/p/6045499.html#top https://blog.csdn.net/xiaoputao0903/artic ...
- php观察折模式
<?php class Paper{ private $_observers = array(); public function register($sub){ $this->_obse ...
- linux中文man手册安装
1.下载源码 源码网址 https://src.fedoraproject.org/repo/pkgs/man-pages-zh-CN/ 下载源码 wget https://src.fedorapro ...
- 如何利用showdoc自动生成API文档
介绍 showdoc是一个适合IT团队的文档工具,阅读本文前需要对showdoc有基本了解 .基本介绍可看:https://www.showdoc.cc/help 对于写API文档这件事,虽然说文本编 ...