HDU 6049 17多校2 Sdjpx Is Happy(思维题difficult)
1.He can divides soldiers into K disjoint non-empty subarrays.
2.He can sort a subarray many times untill a subarray is sorted in increasing order.
3.He can choose just two subarrays and change thier positions between themselves.
Consider A = [1 5 4 3 2] and P = 2. A possible soldiers into K = 4 disjoint subarrays is:A1 = [1],A2 = [5],A3 = [4],A4 = [3 2],After Sorting Each Subarray:A1 = [1],A2 = [5],A3 = [4],A4 = [2 3],After swapping A4 and A2:A1 = [1],A2 = [2 3],A3 = [4],A4 = [5].
But he wants to know for a fixed permutation ,what is the the maximum number of K?
Notice: every soldier has a distinct number from 1~n.There are no more than 10 cases in the input.
For every case:
Next line is n.
Next line is the number for the n soildiers.
Every case a line.
Test1: Same as walk through in the statement. Test2: [4 5] [1 2 3] Swap the 2 blocks: [1 2 3] [4 5].
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
#define MAXN 3005 int a[MAXN],res,n;
int mi[MAXN][MAXN],mx[MAXN][MAXN];
//mi[i][j]表示从i到j的最小值,mx[i][j]表示从i到j的最大值
int f[MAXN][MAXN],r[MAXN];
//f[i][j]表示从i到j可以分成的区间数,r[i]表示最近一次从i开始的区间的右端(方便更新) void init()//第一步,分块
{
memset(mi,,sizeof(mi));
memset(mx,,sizeof(mx));
memset(f,,sizeof(f));
memset(r,,sizeof(r));
for(int i=;i<=n;i++)
{
mi[i][i]=a[i];
mx[i][i]=a[i];
f[i][i]=;
r[i]=i;
}
//为mi,mx赋值
for(int i=;i<=n;i++)
for(int j=i+;j<=n;j++)
{
mx[i][j]=max(a[j],mx[i][j-]);
mi[i][j]=min(a[j],mi[i][j-]);
}
//为f数组赋值
for(int t=;t<=n;t++)//t在枚举区间长度
for(int i=;i+t-<=n;i++)
{
int j=i+t-;
//不是连续的一段无法分区间
if(mx[i][j]-mi[i][j]!=t-)
f[i][j]=;
else
{
//j一定大于r[i]
if(mi[i][r[i]]>mi[i][j])
f[i][j]=;
else
f[i][j]=f[i][r[i]]+f[r[i]+][j];
r[i]=j;//这个r数组很精华
}
}
} void solve()//第二步,枚举找交换区间
{
int k;
res=max(,f[][n]);//WA点,一开始写成res=1就WA了
//先枚举seg_a
for(int i=;i<=n;i++)
for(int j=i;j<=n;j++)
{
//满足条件才能继续枚举seg_b
if(i==||(f[][i-]!=&&mi[][i-]==))
{
k=mx[i][j];
if(f[i][j]&&(k==n||(f[k+][n]!=&&mx[k+][n]==n)))
{
for(int t=j+;t<=k;t++)
{
if(f[t][k]&&mi[t][k]==i)
{
//printf("%d %d %d %d %d\n",i,j,t,k,f[1][i-1]+1+f[j+1][t-1]+1+f[k+1][n]);
res=max(res,f[][i-]++f[j+][t-]++f[k+][n]);
}
}
}
}
}
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
init();
solve();
printf("%d\n",res);
}
return ; }
HDU 6049 17多校2 Sdjpx Is Happy(思维题difficult)的更多相关文章
- HDU 6140 17多校8 Hybrid Crystals(思维题)
题目传送: Hybrid Crystals Problem Description > Kyber crystals, also called the living crystal or sim ...
- HDU 6034 17多校1 Balala Power!(思维 排序)
Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He want ...
- HDU 6143 17多校8 Killer Names(组合数学)
题目传送:Killer Names Problem Description > Galen Marek, codenamed Starkiller, was a male Human appre ...
- HDU 6045 17多校2 Is Derek lying?
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6045 Time Limit: 3000/1000 MS (Java/Others) Memory ...
- HDU 6124 17多校7 Euler theorem(简单思维题)
Problem Description HazelFan is given two positive integers a,b, and he wants to calculate amodb. Bu ...
- HDU 3130 17多校7 Kolakoski(思维简单)
Problem Description This is Kolakosiki sequence: 1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1……. This seq ...
- HDU 6038 17多校1 Function(找循环节/环)
Problem Description You are given a permutation a from 0 to n−1 and a permutation b from 0 to m−1. D ...
- HDU 6103 17多校6 Kirinriki(双指针维护)
Problem Description We define the distance of two strings A and B with same length n isdisA,B=∑i=0n− ...
- HDU 6098 17多校6 Inversion(思维+优化)
Problem Description Give an array A, the index starts from 1.Now we want to know Bi=maxi∤jAj , i≥2. ...
随机推荐
- UI基础三:简单的BOL报表开发
巧了...刚好一个需求,就直接来撸起来吧. 需要做一个报表: 1.创建查询结构和结果结构 2.创建实施类: SE24创建ZCL_JPEXPORT_ORDER_IL 更改父类:CL_WCF_GENIL_ ...
- windows 系统分布式版本控制 git 使用学习
1. 在 Windows 上安装 Git 在Windows上使用Git,可以从Git官网直接下载安装程序,(网速慢的同学请移步国内镜像),然后按默认选项安装即可. 安装完成后,在开始菜单里找到“Git ...
- 抓包工具Charles的简单使用
一.Charles破解 下载安装及破解方法: 1.下载charles并安装 云盘下载地址:Windows 64bit 32bit 2.安装后先打开Charles一次(Windows版可以忽略此步 ...
- Object对象的浅拷贝与深拷贝方法详解
/* ===================== 直接看代码 ===================== */ <!DOCTYPE html> <html> <head& ...
- 理解javascript封装
封装可以被定义为对对象的内部数据表现形式和实现细节进行隐藏.通过封装可以强制实施信息隐藏. 在JavaScript中,并没有显示的声明私有成员的关键字等.所以要想实现封装/信息隐藏就需要从另外的思路出 ...
- 浅谈mysql中各种表空间(tablespaces)的概念
mysql中,会涉及到各种表空间的概念,虽然,很多方面这些概念和Oracle有相似性,但也有很多不同的地方,初学者很容易被这些概念弄的晕头转向,从而,混淆这些概念的区别和理解,下面,就简要介绍和说明一 ...
- Python爬虫原理
前言 简单来说互联网是由一个个站点和网络设备组成的大网,我们通过浏览器访问站点,站点把HTML.JS.CSS代码返回给浏览器,这些代码经过浏览器解析.渲染,将丰富多彩的网页呈现我们眼前: 一.爬虫是什 ...
- APK骨架分析
APK反编译的一般步骤是: 使用apktool将apk文件解压(后辍apk改为rar用winrar也可解压但这样不能解密res/value目录下的各文件),厉害的可以直接静态分析smali文件(ida ...
- hibernate配置log
hibernate依赖jboss-logging,通过它选择对应的对应的日志包,选择的逻辑课查看具体代码org.jboss.logging.LoggerProviders. 先通过系统变量(org.j ...
- JQuery对象和DOM对象的区别与转换
刚开始学习JQuery,经常分不清楚哪些是JQuery对象,哪些是DOM对象,了解它们之间的关系是很有必要的. 1.DOM对象和JQuery对象的区别 1) DOM对象 DOM是Document O ...