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 ...
随机推荐
- thinkphp模型创建
- 详解MySQL大表优化方案
单表优化 除非单表数据未来会一直不断上涨,否则不要一开始就考虑拆分,拆分会带来逻辑.部署.运维的各种复杂度,一般以整型值为主的表在千万级以下,字符串为主的表在五百万以下是没有太大问题的.而事实上很多时 ...
- Codeforces 946D Timetable(预处理+分组背包)
题目链接:http://codeforces.com/problemset/problem/946/D 题目大意:有n个字符串,代表n天的课表,1表示这个时间要上课,0表示不要上课,一天在学校时间为第 ...
- (六)MyBatis杂项
第一节:处理CLOB.BLOB类型数据 第二节:传入多个输入参数 第三节:MyBatis分页 1,逻辑分页 2,物理分页 MyBatis默认情况下,MyBatis启用一级缓存,即同一个SqlSessi ...
- 宝塔Linux常用命令
https://www.bt.cn/bbs/thread-1186-1-1.html 2017年3月8日发布全新架构的宝塔Linux 面板3.1Beta版,到现在的5.2.0正式版,历经100多天打磨 ...
- more命令 less命令
more命令是一个基于vi编辑器文本过滤器,它以全屏幕的方式按页显示文本文件的内容,支持vi中的关键字定位操作.more名单中内置了若干快捷键,常用的有H(获得帮助信息),Enter(向下翻滚一行), ...
- Android Activity、Service、BroadcastReceiver 的生命周期
Activity.Service.BroadcastReceiver这三个组建是Android开发中最常使用到的组件,在它们的生命周期的各个阶段我们需要针对性的做些事情,了解这些组件的生命周期有利于我 ...
- day1作业:编写登录窗口一个文件实现
思路: 1.参考模型,这个作业我参考了linux的登录认证流程以及结合网上银行支付宝等锁定规则: 1)认证流程参考的是Linux的登录:当你输入完用户名密码后再验证用户名是否存在用户是否被锁定,然后在 ...
- 支持多个title,解决主副标题分别对齐
- Rookey.Frame之实体FluentValidation验证
昨天给大家介绍了Rookey.Frame框架的实体设计,今天继续跟大家分享实体的FluentValidation验证,在Rookey.Frame框架中可以设置多种验证方式:FluentValidati ...