hdu 6049---Sdjpx Is Happy(区间DP+枚举)
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.
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int N=3e3+;
int f[N][N];
int mx[N][N],mn[N][N],R[N]; int main()
{
///cout << "Hello world!" << endl;
int T; cin>>T;
while(T--)
{
int n; scanf("%d",&n);
memset(f,,sizeof(f));
for(int i=;i<=n;i++)
{
scanf("%d",&mx[i][i]);
mn[i][i]=mx[i][i];
f[i][i]=;
R[i]=i;
}
for(int i=;i<=n;i++)
{
for(int j=i+;j<=n;j++)
{
mx[i][j]=max(mx[i][j-],mx[j][j]);
mn[i][j]=min(mn[i][j-],mn[j][j]);
}
}
for(int i=;i<=n;i++)
{
for(int j=;j+i-<=n;j++)
{
int k=j+i-;
if(mx[j][k]-mn[j][k]+!=i) f[j][k]=;
else {
if(mn[j][k]!=mn[j][R[j]]) f[j][k]=;
else f[j][k]=f[j][R[j]]+f[R[j]+][k];
R[j]=k;
}
}
}
int ans=f[][n];
for(int i=;i<=n;i++)
{
for(int j=i;j<=n;j++)
{
if(!f[i][j]) continue;
if(i== || (f[][i-]&&mn[][i-]==))
{
int k=mx[i][j];
if(k==n || (f[k+][n]&&mx[k+][n]==n))
{
for(int t=j+;t<=k;t++)
{
if(f[t][k]&&mn[t][k]==i)
ans=max(ans,f[][i-]++f[j+][t-]++f[k+][n]);
}
}
}
}
}
printf("%d\n",ans);
}
return ;
}
hdu 6049---Sdjpx Is Happy(区间DP+枚举)的更多相关文章
- HDU 6049 - Sdjpx Is Happy | 2017 Multi-University Training Contest 2
思路来源于 FXXL - - 一个比较奇怪的地方就是第三步可以不做,也就是ans至少为1,听说场内有提问的,然后 admin 说可以不做- - (wa的我心烦) /* HDU 6049 - Sdjpx ...
- hdu 4597 + uva 10891(一类区间dp)
题目链接:http://vjudge.net/problem/viewProblem.action?id=19461 思路:一类经典的博弈类区间dp,我们令dp[l][r]表示玩家A从区间[l, r] ...
- HDU 2476 String painter (区间DP)
题意:给出两个串a和b,一次只能将一个区间刷一次,问最少几次能让a=b 思路:首先考虑最坏的情况,就是先将一个空白字符串刷成b需要的次数,直接区间DP[i][j]表示i到j的最小次数. 再考虑把a变成 ...
- HDU 4597 Play Game(区间DP(记忆化搜索))
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4597 题目大意: 有两行卡片,每个卡片都有各自的权值. 两个人轮流取卡片,每次只能从任一行的左端或右端 ...
- HDU 5115 Dire Wolf ——(区间DP)
比赛的时候以为很难,其实就是一个区间DP= =..思路见:点我. 区间DP一定要记住先枚举区间长度啊= =~!因为区间dp都是由短的区间更新长的区间的,所以先把短的区间更新完.. 代码如下: #inc ...
- HDU 5151 Sit sit sit 区间DP + 排列组合
Sit sit sit 问题描述 在一个XX大学中有NN张椅子排成一排,椅子上都没有人,每张椅子都有颜色,分别为蓝色或者红色. 接下来依次来了NN个学生,标号依次为1,2,3,...,N. 对于每个学 ...
- hdu 5115 Dire Wolf(区间dp)
Problem Description Dire wolves, also known as Dark wolves, are extraordinarily large and powerful w ...
- HDU 2476 String painter(区间DP)
String painter Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU 4745 Two Rabbits(区间DP,最长非连续回文子串)
Two Rabbits Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Total ...
随机推荐
- 【Django】关于上传图片遇到的问题
今天测试上传图片的时候,发现一只报错说找不到文件:FileNotFoundError 通过检查路径的输出,发现首先在settings配置路径的时候有问题 MEDIA_ROOT=os.path.join ...
- sqlserver truncate清空表时候,无法删除 'B表',因为该表正由一个 FOREIGN KEY 约束引用。
外键: 查询:select object_name(a.parent_object_id) 'tables' from sys.foreign_keys a where a.referenced_ ...
- SpringBoot集成Jasypt安全框架,配置文件内容加密
我们在SpringBoot项目中的yml或者properties配置文件中都是明文的,相对而言安全性就低了很多.都知道配置文件中的都是一些数据库连接用户名密码啊.一些第三方密钥等信息.所以我们谨慎点, ...
- Linux知识扩展二:lsof命令
转:https://www.cnblogs.com/the-study-of-linux/p/5501593.html 1. lsof :list open file 显示linux下打开的文件信息. ...
- Solidity合约间的调用-1
当调用其它合约的函数时,可以通过选项.value(),和.gas()来分别指定,要发送的ether量(以wei为单位),和gas值. pragma solidity ^; contract InfoF ...
- jquery判断是否是空对象 不含任何属性
code function isEmptyObject(e) { var t; for (t in e) return !1; return !0 }
- 20170805_Elasticsearch_简介和安装
官网地址: https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started.html Elk 是一个可高 ...
- You are using pip version 9.0.1, however version 9.0.3 is available.
1,pip不能用了,提示:You are using pip version 8.1.1, however version 9.0.1 is available.网上搜索了一箩筐的安装程序,各种安装, ...
- Java 装箱和拆箱
1.装箱机制 基础类型引用到其包装类型,这样就可以调用其各种方法. 例如,我们声明: Integer a = 1; 其在编译过程中会自动解释成: Integer a = Integer.valueOf ...
- SWPU-ACM集训队周赛之组队赛(3-11) C题题解
点这里去看题 模拟,注意细节 #include<stdio.h> #include<string.h> int main() { ]; //q[]储存正负信息 scanf(&q ...