http://acm.hdu.edu.cn/showproblem.php?pid=5087

题意求第二长的上升序列。 在求最长上升序列的同时加上一个数组,来记录以i为结尾的有多少条序列。如果n+1为结尾有多条,就输出dp[n+1]-1;

否则在这个最长的序列上每一个节点是不是都是num[i]==1,如果是,就输出dp[n+1]-2;否则输出dp[n+1]-1;

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 1005
#define LL int
using namespace std; int t;
LL a[maxn];
int n;
int dp[maxn];
int num[maxn]; int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
memset(dp,,sizeof(dp));
memset(num,,sizeof(num));
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
}
a[n+]=;
for(int i=; i<=n+; i++)
{
dp[i]=;
num[i]=;
for(int j=; j<i; j++)
{
if(a[j]<a[i]&&dp[i]<dp[j]+)
{
num[i]=;
dp[i]=dp[j]+;
}
else if(a[j]<a[i]&&dp[i]==dp[j]+)
{
num[i]++;
}
}
}
if(num[n+]>) printf("%d\n",dp[n+]-);
else
{
int pos=n+,j;
while(pos>&&num[pos]==)
{
for(j=pos-; j>=; j--)
{
if(dp[j]+==dp[pos]&&a[j]<a[pos]) break;
}
pos=j;
}
if(pos==) printf("%d\n",dp[n+]-);
else printf("%d\n",dp[n+]-);
}
}
return ;
}

hdu 5087 Revenge of LIS II的更多相关文章

  1. hdu 5087 Revenge of LIS II ( LIS ,第二长子序列)

    链接:hdu 5087 题意:求第二大的最长升序子序列 分析:这里的第二大指的是,全部的递增子序列的长度(包含相等的), 从大到小排序后.排在第二的长度 cid=546" style=&qu ...

  2. hdu 5087 Revenge of LIS II (DP)

    题意: N个数,求第二长上升子序列的长度. 数据范围: 1. 1 <= T <= 1002. 2 <= N <= 10003. 1 <= Ai <= 1 000 0 ...

  3. hdoj 5087 Revenge of LIS II 【第二长单调递增子】

    称号:hdoj 5087 Revenge of LIS II 题意:非常easy,给你一个序列,让你求第二长单调递增子序列. 分析:事实上非常easy.不知道比赛的时候为什么那么多了判掉了. 我们用O ...

  4. HDOJ 5087 Revenge of LIS II DP

    DP的时候记录下能否够从两个位置转移过来. ... Revenge of LIS II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: ...

  5. HDU 5078 Revenge of LIS II(dp LIS)

    Problem Description In computer science, the longest increasing subsequence problem is to find a sub ...

  6. HDU5087——Revenge of LIS II(BestCoder Round #16)

    Revenge of LIS II Problem DescriptionIn computer science, the longest increasing subsequence problem ...

  7. hdu5087——Revenge of LIS II

    Revenge of LIS II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  8. BestCoder16 1002.Revenge of LIS II(hdu 5087) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5087 题目意思:找出第二个最长递增子序列,输出长度.就是说,假如序列为 1 1 2,第二长递增子序列是 ...

  9. HDU5087 Revenge of LIS II (LIS变形)

    题目链接:pid=5087">http://acm.hdu.edu.cn/showproblem.php?pid=5087 题意: 求第二长的最长递增序列的长度 分析: 用step[i ...

随机推荐

  1. 谈"http get和post的区别"

    --以下内容如有各种问题,烦请指出,谢谢各位^_^-- 最基本的Java程序员面试题都有这个题 --http get和post的区别? 不少人大学还没毕业就知道,就算不知道也会去搜,我记得我快毕业那会 ...

  2. 【.NET调用Python脚本】C#调用python requests类库报错 'module' object has no attribute '_getframe' - IronPython 2.7

    最近在开发微信公众号,有一个自定义消息回复的需求 比如用户:麻烦帮我查询一下北京的天气? 系统回复:北京天气,晴,-℃... 这时候需要根据关键字[北京][天气],分词匹配需要执行的操作,然后去调用天 ...

  3. 双系统如何正确的使用修复BCD工具分享

    安装双系统时候,用于种种原因会导致开机启动只显示一个系统,此时需要修复下BCD即可. 下面介绍下两个修复BCD工具软件: 1.easybcd(双系统引导修复工具) v2.2.0.182 汉化版 下载地 ...

  4. java 连接数据库mysql的方法

    1.把那个文件配置好环境变量. 2.创建数据库,插入数据 注意的地方: (1)环境变量 classpath(可大写,也可以小写,可放在个人变量,也可以试系统变量) 里面的值 F:\mysql-conn ...

  5. 亲测 安装 mysql5.5 64位

    1.选择 customn 更改安装目录2.选择 develop 模式,默认,占用内存较小. server machine 中等内存 dedicate mysql server machine 专用服务 ...

  6. sizeof操作符-结构体与类大小

    导读 sizeof是C/C++一个难点,当在自定义类上应用sizeof操作符时,总会出现意想不到的结果,下面,我们就来探讨一下sizeof这个操作符! 目录 1. sizeof与strlen的区别 2 ...

  7. CoreText实现图文混排之点击事件

    今天呢,我们继续把CoreText图文混排的点击事件补充上,这样我们的图文混排也算是圆满了. 哦,上一篇的链接在这里 http://www.jianshu.com/p/6db3289fb05d Cor ...

  8. android中的数据库操作(转)

    android中的数据库操作 android中的应用开发很难避免不去使用数据库,这次就和大家聊聊android中的数据库操作. 一.android内的数据库的基础知识介绍 1.用了什么数据库   an ...

  9. git 取消/添加 某文件的跟踪

    如果我们不小心将某个文件加入了 git 版本控制,但是突然又不想继续跟踪控制这个文件了,怎么办呢? 使用 git update-index 即可. 不想继续追踪某个文件 git update-inde ...

  10. 遍历aspx页面中所有的指定控件

    //1.遍历页面中所有的TextBox,并将值设置成String.Empty for (int j = 0; j < this.Controls.Count; j++){      foreac ...