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

求数列次长升序串的长度

还是dp求最长升序串的长度,再开一个数组记录对于dp值的串的个数

最后看一下最长字符串的个数是一个的话,显然次长的是最长的长度-1,否则就是最长的那个字符串的长度

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define clr0(x) memset(x,0,sizeof(x))
#define clr1(x) memset(x,-1,sizeof(x))
#define eps 1e-9
const double pi = acos(-1.0);
typedef long long LL;
typedef unsigned long long ULL;
const int modo = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int inf = 0x3fffffff;
const LL _inf = 1e18;
const int maxn = 2005,maxm = 10005;
int dp[maxn],s[maxn],cnt[maxn];
int main()
{
int _;RD(_);
int n;
while(_--){
RD(n);
for(int i = 1;i <= n;++i)
RD(s[i]),dp[i] = cnt[i] = 1;
int ans = 0,_cnt = 0;
for(int i = 2;i <= n;++i){
for(int j = 1;j < i;++j){
if(s[i] > s[j]){
if(dp[i] < dp[j] + 1){
dp[i] = dp[j]+1;
cnt[i] = cnt[j];
}else if(dp[i] == dp[j] + 1){
cnt[i] += cnt[j];
}
}
}
ans = max(ans,dp[i]);
}
for(int i = 1;i <= n;++i)
if(ans == dp[i])
_cnt += cnt[i];
printf("%d\n",ans - (_cnt == 1));
}
return 0;
}

												

hdu 5087 次长升序串的长度的更多相关文章

  1. hdu 5087(次长上升子序列)

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

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

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

  3. HDU 5087 (线性DP+次大LIS)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5087 题目大意:求次大LIS的长度.注意两个长度相同的LIS大小比较,下标和大的LIS较大. 解题思 ...

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

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

  5. HDU 6084 寻找母串(卡特兰数)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6084 [题目大意] 对于一个串S,当它同时满足如下条件时,它就是一个01偏串: 1.只由0和1两种 ...

  6. hdu 5087 Revenge of LIS II

    http://acm.hdu.edu.cn/showproblem.php?pid=5087 题意求第二长的上升序列. 在求最长上升序列的同时加上一个数组,来记录以i为结尾的有多少条序列.如果n+1为 ...

  7. 返回字符串中最长连续相同字串的长度---正则实现与JavaScript实现

    JavaScript 实现 let str = 'AAABBAACCAAAADDE' function continuousString(str) { let finalObj = {} let te ...

  8. HDU 3068 回文串-Manacher

    题意链接:http://acm.hdu.edu.cn/showproblem.php?pid=3068 题意:中文题. 思路:Manacher模板题 #include<iostream> ...

  9. 【HDU 2203】亲和串

    题 题意 给你一个字符串s1,字符串s2,s1循环移位,使s2包含在s1中,则s2 是s1的亲和串 分析 把s1自身复制一遍接在后面. 方法一: 用strstr函数. 方法二: KMP算法. 方法三: ...

随机推荐

  1. PHP 语句和时间函数

    语句 1.分支语句 (1)if例子:$a=9;$b=5;if($a>$b){echo $a."比".$b."大";}else{echo $a." ...

  2. iOS.Crash.Case-[__NSArrayM objectForKeyedSubscript:]

    1. [__NSArrayM objectForKeyedSubscript:]: unrecognized selector sent to instance - source code and s ...

  3. Tools.Eclipse.HowToImportAnAndroidLibraryProjectIntoWorkspace

    1. File->New->Other Picture-1 2. Select "Android Project from Existing Code", and cl ...

  4. iOS.WWDC

    1. ASCIIwwdc: Searchable full-text transcripts of WWDC sessions http://asciiwwdc.com

  5. Go语言之讲解GOROOT、GOPATH、GOBIN

    Go是一门全新的静态类型开发语言,具有自动垃圾回收,丰富的内置类型,函数多返回值,错误处理,匿名函数,并发编程,反射等特性. go命令依赖一个重要的环境变量:$GOPATH GOPATH允许多个目录, ...

  6. Job for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details.

    环境:Ubuntu 16.04.1 + Django  1.11.15 + Apache 2.4.18 + python 3.5 此篇文章内容提到的第几步,对照以下链接中的步骤 百度云的ubuntu1 ...

  7. Java中创建对象的四种方法

    第一种 使用new关键字 第二种 使用反射技术:1)通过Class类的newInstance()方法:2)通过Constructor类的newInstance方法 第三种 通过Object类的clon ...

  8. 2019,UI设计师必备神器

      2019年将会是你全新起航的一年,相信你已经制定了很多规划,正在开启第一步的推动. 作为对UI设计师更大程度的支持,今天特意为你分享一款释放你双手的设计神器.让你可以把时间和精力投入到设计本身,这 ...

  9. 【Redis】安装 Redis接口时异常 ,系统ruby版本过低

    场景 操作系统Linux CentOS 7.2,安装Redis接口时,使用命令:gem install redis ,用于系统ruby版本过低,报错“redis requires Ruby versi ...

  10. TCP的11种状态(转载)

    TCP的11种状态 TCP三次握手建立连接 Tcp头部 六个标志位中,我们要用到三个: SYN:SYN= 1 表示这是一个连接请求或连接接受报文.在建立连接时用来进行同步序号(个人理解是,在建立连接的 ...