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 ...
随机推荐
- springboot 配置文件 .properties和.yml的写法区别
例如 : redis配置的properties或yml文件,如下: spring.redis.cluster.nodes[]= spring.redis.cluster.nodes[]= 或 s ...
- jquery ajaxform上传文件返回不提示信息的问题
在使用jquery的ajaxform插件进行ajax提交表单并且上传文件的时候,返回类型datatype :json但是后台通过写出一个json对象后,在执行完以后没有进入success函数,而是直接 ...
- 数据挖掘方面重要会议的最佳paper集合
数据挖掘方面重要会议的最佳paper集合,兴许将陆续分析一下内容: 主要有KDD.SIGMOD.VLDB.ICML.SIGIR KDD (Data Mining) 2013 Simple and De ...
- 自己动手写shell之chgrp,chown,chmod
1.chgrp实现 #include <grp.h> #include <unistd.h> void chgrp(char * groupname,char * filena ...
- 浅析mysql 共享表空间与独享表空间以及他们之间的转化
innodb这种引擎,与MYISAM引擎的区别很大.特别是它的数据存储格式等.对于innodb的数据结构,首先要解决两个概念性的问题: 共享表空间以及独占表空间.什么是共享表空间和独占表空间共 ...
- JavaScript--execCommand指令集
execCommand方法是执行一个对当前文档,当前选择或者给出范围的命令.处理Html数据时常用 如下格式:document.execCommand(sCmd,交互方式, 动态参数) .其中:sCm ...
- Entity Framework CodeFirst------数据迁移(二)
众所周知当我们的项目涉及到数据库时,随着需求或大或小的 变更后,我们之前设计好的数据模型会发生部分的更改,导致数据表.或者数据字段的增加.修改等,这个时候我们就需要对数据库结构进行修改,如果我们之前采 ...
- git 取消/添加 某文件的跟踪
如果我们不小心将某个文件加入了 git 版本控制,但是突然又不想继续跟踪控制这个文件了,怎么办呢? 使用 git update-index 即可. 不想继续追踪某个文件 git update-inde ...
- Web项目练习总结(错误校正篇)
老师布置任务,从SVN上弄个项目来练练手,熟悉下过程. myeclipse安装SVN 然后把MobileManageSys下下来 然后漫长的等待... 然后配置数据库,导入,这里用的是SQLyog,其 ...
- Javascript 获取url参数,hash值 ,cookie
/** * 获取请求参数 * @param key * @returns {*} */ function getRequestParameter(key){ var params = getReque ...