HDU5087 Revenge of LIS II (LIS变形)
题目链接: pid=5087">http://acm.hdu.edu.cn/showproblem.php?pid=5087
题意:
求第二长的最长递增序列的长度
分析:
用step[i]表示以i结尾的最长上升序列的长度,dp[i]表示到i的不同的最长的子序列的个数
然后最后推断最长的子序列的个数是否大于1是的话输出Max,否则输出Max-1
代码例如以下:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 1005;
int step[maxn],dp[maxn], num[maxn];
int main ()
{
int T;
scanf("%d", &T);
while(T--){
int n;
scanf("%d", &n);
memset(dp, 0, sizeof(dp));
memset(step, 0, sizeof(step));
dp[0] = 1;
for(int i = 1; i <= n; i++)
scanf("%d", &num[i]);
int Max = -1;
for(int i = 1; i <= n; i++){
for(int j = 0; j < i; j++){
if(num[i] > num[j]){
if(step[j]+1 > step[i]){
step[i] = step[j] + 1;
dp[i] = dp[j];
}
else if(step[j] + 1 == step[i])
dp[i] += dp[j];
}
}
Max = max(Max, step[i]);
}
int flag = 0;
int ok = 1;
for(int i = 1; i <= n; i++){
if(step[i] == Max){
if(dp[i] > 1) ok = 0;
else{
if(flag) ok = 0;
flag = 1;
}
}
}
printf("%d\n", Max - ok );
}
return 0;
}
HDU5087 Revenge of LIS II (LIS变形)的更多相关文章
- hdu 5087 Revenge of LIS II ( LIS ,第二长子序列)
链接:hdu 5087 题意:求第二大的最长升序子序列 分析:这里的第二大指的是,全部的递增子序列的长度(包含相等的), 从大到小排序后.排在第二的长度 cid=546" style=&qu ...
- 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 ...
- HDOJ 5087 Revenge of LIS II DP
DP的时候记录下能否够从两个位置转移过来. ... Revenge of LIS II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
- hdoj 5087 Revenge of LIS II 【第二长单调递增子】
称号:hdoj 5087 Revenge of LIS II 题意:非常easy,给你一个序列,让你求第二长单调递增子序列. 分析:事实上非常easy.不知道比赛的时候为什么那么多了判掉了. 我们用O ...
- HDU5088——Revenge of Nim II(高斯消元&矩阵的秩)(BestCoder Round #16)
Revenge of Nim II Problem DescriptionNim is a mathematical game of strategy in which two players tak ...
- HDOJ 5088 Revenge of Nim II 位运算
位运算.. .. Revenge of Nim II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- hdu5087 Revenge of LIS II (dp)
只要理解了LIS,这道题稍微搞一下就行了. 求LIS(最长上升子序列)有两种方法: 1.O(n^2)的算法:设dp[i]为以a[i]结尾的最长上升子序列的长度.dp[i]最少也得是1,就初始化为1,则 ...
- HDU 5078 Revenge of LIS II(dp LIS)
Problem Description In computer science, the longest increasing subsequence problem is to find a sub ...
随机推荐
- (三)Jsoup 使用选择器语法查找 DOM 元素
第一节: Jsoup 使用选择器语法查找 DOM 元素 Jsoup使用选择器语法查找DOM元素 我们前面通过标签名,Id,Class样式等来搜索DOM,这些是不能满足实际开发需求的, 很多时候我们需要 ...
- GreenPlum学习笔记:基础知识
一.介绍 GreenPlum分布式数据仓库,大规模并行计算技术. 无共享/MPP核心架构 Greenplum数据库软件将数据平均分布到系统的所有节点服务器上,所以节点存储每张表或表分区的部分行,所有数 ...
- Hive(九)Hive 执行过程实例分析
一.Hive 执行过程概述 1.概述 (1) Hive 将 HQL 转换成一组操作符(Operator),比如 GroupByOperator, JoinOperator 等 (2)操作符 Opera ...
- 【LOJ】 #2545. 「JXOI2018」守卫
题解 只会蠢蠢的\(n^3\)--菜啊-- 我们发现最右的端点一定会选,看到的点一定是当前能看到的斜率最小的点变得更小一点,记录下这个点,在我们遇到一个看不到的点的时候,然后只用考虑R到它斜率最小的这 ...
- Bootstrap--响应式导航条布局
<!DOCTYPE html> <html> <head> <meta name="viewport" content="wid ...
- 黑马程序员_java基础笔记(11)...反射
—————————— ASP.Net+Android+IOS开发..Net培训.期待与您交流! —————————— 1,字节码.2,Constructor类.3,Field类.4,Method类.5 ...
- 8-15 Shuffle uva12174
题意: 你正在使用的音乐播放器有一个所谓的乱序功能,即随机打乱歌曲的播放顺序.假设一共有s首歌,则一开始会给这s首歌随机排序,全部播放完毕后再重新随机排序.继续播放,依此类推.注意,当s首歌播放完毕之 ...
- 在 Pandas 中更改列的数据类型
import pandas as pd import numpy as np a = [['a', '1.2', '4.2'], ['b', '70', '0.03'], ['x', '5', '0' ...
- CAS和Synchronized
CAS compareAndSwap 原理 CAS(V,E,N) V表示要更新的变量 E表示预期值 N表示新值 (当前值和底层值一样时候,才更新) 传入的值是工作内存,底层的值是主内存,工作内 ...
- Ubuntu安装redis和redis-php扩展
通过apt-get安装的redis使用方法 sudo apt-get install redis-server sudo apt-get install php-redis vim /etc/redi ...