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 ...
随机推荐
- 在树莓派1B上编译安装lnmp服务器
最近一周给部门内部搭建考试系统,选择使用PHPEMS.这是个开源的系统,唯一缺点是PHP的版本比较低,只能使用5.2或5.3.而我的树莓派系统更新后使用apt-get安装得到的PHP版本为5.4.由于 ...
- poj 3422 (费用流)
从左上角到有下角k次能获得的最大值. 跟hdu 2686一样的题目,这题一个点可以重复走,只能得到一次值. #include<stdio.h> #include<string.h&g ...
- [AngularJS] Enable Animations Explicitly For A Performance Boost In AngularJS
http://www.bennadel.com/blog/2935-enable-animations-explicitly-for-a-performance-boost-in-angularjs. ...
- Unix文件操作
一.概述 Unix文件操作常用函数包括open.close.creat.lseek.dup.dup2.fcntl等, 其中open.creat. fcntl函数需要包含头文件<fcntl.h&g ...
- mcrypt.h not found. Please reinstall libmcrypt
在centos上对php5.6进行源码安装的时候, 出现了如题所示错误提示, 原因是由于centos源不能安装libmcrypt-devel,由于版权的原因没有自带mcrypt的包 解决办法使用php ...
- vsftp配置主动模式和被动模式
配置文件:/etc/vsftpd/vsftpd.conf 主动模式配置方法: 主动式连接使用的数据通道 connect_from_port_20=YES 支持数据流的被动式连接模式 pasv_enab ...
- 解决CSS中float:left后需要clear:both清空的繁琐步骤(转)
之前,因为公司专门有CSS+DIV的切片设计师,所以我一直都是注重程序的设计与开发.现在,因为接了一些Web网站的项目需要制作,就在空闲时间学习起了CSS.Jquery. 现在,大部分的横排导航都 ...
- angularjs项目中关于服务的应用
/** *普通ajax请求公共服务 */ mainModule.factory('myService',function($http,$q){ var service = {}; var baseUr ...
- Cacti以MB为单位监控流量
Cacti自带的流量监控阀值模板为“Interface – Traffic”,只能监控bytes,在添加阀值之后,报警的流量信息以bytes为单位,查看很不友好,可以通过以下方法将btyes转换成MB ...
- oracle事务特性详解
原子性 事务是一个完整的操作.事务的各步操作是不可分的(原子的):要么都执行,要么都不执行. -- 创建表 create table account_money ( id number(4) not ...