hdu 5087 Revenge of LIS II
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的更多相关文章
- hdu 5087 Revenge of LIS II ( LIS ,第二长子序列)
链接:hdu 5087 题意:求第二大的最长升序子序列 分析:这里的第二大指的是,全部的递增子序列的长度(包含相等的), 从大到小排序后.排在第二的长度 cid=546" style=&qu ...
- hdu 5087 Revenge of LIS II (DP)
题意: N个数,求第二长上升子序列的长度. 数据范围: 1. 1 <= T <= 1002. 2 <= N <= 10003. 1 <= Ai <= 1 000 0 ...
- hdoj 5087 Revenge of LIS II 【第二长单调递增子】
称号:hdoj 5087 Revenge of LIS II 题意:非常easy,给你一个序列,让你求第二长单调递增子序列. 分析:事实上非常easy.不知道比赛的时候为什么那么多了判掉了. 我们用O ...
- HDOJ 5087 Revenge of LIS II DP
DP的时候记录下能否够从两个位置转移过来. ... Revenge of LIS II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
- HDU 5078 Revenge of LIS II(dp LIS)
Problem Description In computer science, the longest increasing subsequence problem is to find a sub ...
- HDU5087——Revenge of LIS II(BestCoder Round #16)
Revenge of LIS II Problem DescriptionIn computer science, the longest increasing subsequence problem ...
- hdu5087——Revenge of LIS II
Revenge of LIS II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- BestCoder16 1002.Revenge of LIS II(hdu 5087) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5087 题目意思:找出第二个最长递增子序列,输出长度.就是说,假如序列为 1 1 2,第二长递增子序列是 ...
- HDU5087 Revenge of LIS II (LIS变形)
题目链接:pid=5087">http://acm.hdu.edu.cn/showproblem.php?pid=5087 题意: 求第二长的最长递增序列的长度 分析: 用step[i ...
随机推荐
- javaweb项目的优化 - 几番思念
简单地来看一个浏览器用户访问的流程: 浏览器->服务器->返回结果显示 这么简单地看,可能想得到的优化手段很少,常见的可能就是优化sql,加快数据库处理:加个缓存,加快返回:使用静态文件 ...
- Java学习的随笔(3)接口
首先是一段<Java编程思想>中,对接口的解释:“interface这个关键字产生一个完全抽象的类,它根本就没有提供任何具体的实现.它允许创建者确定方法名.参数列表.返回类型,但是没有任何 ...
- 工程建立多个source folder
在工程中,想在建立多个source filder,总是报错,报错信息是 Cannot nest 'GzEdu/src/c' inside 'GzEdu/src'. To enable the nest ...
- Android RadioGroup Fragment Viewpager FragmentPagerAdapter 去哪网Fragment嵌套
RadioGroup中的各个选择器 <selector xmlns:android="http://schemas.android.com/apk/res/android"& ...
- Android-Socket传输 GPRS网络
手机使用GPRS网络与server进行Socket通信,代码下载地址:http://download.csdn.net/detail/wu20093346/7768481 用UDP协议与Socket调 ...
- LTTng调试: 一个系统软件工程师的随手涂鸦
http://nanxiao.me/install-lttng/ http://packages.efficios.com/ http://lttng.org/ http://lttng.org/do ...
- win32下进程间通信——共享内存
一.引言 在Windows程序中,各个进程之间常常需要交换数据,进行数据通讯.WIN32 API提供了许多函数使我们能够方便高效的进行进程间的通讯,通过这些函数我们可以控制不同进程间的数据交换 ...
- 没有懂的leetcode
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...
- Oracle中的over(partition by...)分析函数及开窗函数
假设有一张表student Name Score InsertTime (Name:姓名 Score:成绩 InsertTime:考试时间) 张三 20 2015-08-08 ...
- <c:if>判断参数是否同时为空
<c:if test="${empty str}"> str为空</c:if> <c:if test="${not empty str}& ...