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 ...
随机推荐
- readmine项目管理和缺陷跟踪工具
官方网站:http://www.redmine.org/演示地址:http://demo.redmine.org/下载地址:http://www.redmine.org/projects/redmin ...
- 在安装软件CAJViewer时出现,“错误1327。无效驱动器:F:
解决的方法:DOS中输入例如以下命令: [plain] view plaincopy subst F: %TEMP% 回车退出就可以,必要时重新启动电脑. 软件成功安装之后能够执行下面命令,将该虚拟分 ...
- 模板-->常系数线性齐次递推(矩阵快速幂)
如果有相应的OJ题目,欢迎同学们提供相应的链接 相关链接 所有模板的快速链接 Matrix模板 poj_2118_Firepersons,my_ac_code 简单的测试 None 代码模板 /* * ...
- 电脑安装win8.1后 前面板没有声音的解决办法
解决部分朋友在给电脑新安装win8.1系统后出现耳机插入电脑前面板音频口没有声音的问题 百度经验:jingyan.baidu.com 方法/步骤 1 1.安装声卡驱动(必须安装,否则无法完成设置) 2 ...
- JavaScript回调函数的理解
这里是个人对回调函数的一段理解 <!DOCTYPE html> <html> <head> <title>回调函数</title> < ...
- Ecstore后台中显示页面display,page,singlepage方法的区别?
dispaly 显示的页面不包含框架的其他页面,只是本身的页面(使用范围:Ecstore的前端.后端). page 显示的页面包含在框架的里面(使用范围:Ecstore的前端.后端). singlep ...
- (转)dedecms入门
学dedecms一段时间了,把我的入门体会和大家分享一下. 什么是dedecm cms(内容管理系统):现在有各种内容模型,如书评(包括书名,出版社,评论等字段).cms一般有用户后台,网页的用户可以 ...
- 哥的第一个Jquery程序
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs& ...
- (转帖) 有限狀態機FSM coding style整理 (SOC) (Verilog)
来源:http://www.codesoso.net/Record/101092_95120_21.html 来源:http://www.cnblogs.com/oomusou/archive/201 ...
- 配置中的address不能重复
<jaxws:endpoint implementor="com.service.imp.UserServiceImpl" address="/user" ...