题目链接:

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

题意:

求第二长的最长递增序列的长度

分析:

用step[i]表示以i结尾的最长上升序列的长度,dp[i]表示到i的不同的最长的子序列的个数

然后最后推断最长的子序列的个数是否大于1是的话输出Max,否则输出Max-1

代码例如以下:

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. using namespace std;
  5. const int maxn = 1005;
  6. int step[maxn],dp[maxn], num[maxn];
  7. int main ()
  8. {
  9. int T;
  10. scanf("%d", &T);
  11. while(T--){
  12. int n;
  13. scanf("%d", &n);
  14. memset(dp, 0, sizeof(dp));
  15. memset(step, 0, sizeof(step));
  16. dp[0] = 1;
  17. for(int i = 1; i <= n; i++)
  18. scanf("%d", &num[i]);
  19. int Max = -1;
  20. for(int i = 1; i <= n; i++){
  21. for(int j = 0; j < i; j++){
  22. if(num[i] > num[j]){
  23. if(step[j]+1 > step[i]){
  24. step[i] = step[j] + 1;
  25. dp[i] = dp[j];
  26. }
  27. else if(step[j] + 1 == step[i])
  28. dp[i] += dp[j];
  29. }
  30. }
  31. Max = max(Max, step[i]);
  32. }
  33. int flag = 0;
  34. int ok = 1;
  35. for(int i = 1; i <= n; i++){
  36. if(step[i] == Max){
  37. if(dp[i] > 1) ok = 0;
  38. else{
  39. if(flag) ok = 0;
  40. flag = 1;
  41. }
  42. }
  43. }
  44. printf("%d\n", Max - ok );
  45. }
  46. return 0;
  47. }

HDU5087 Revenge of LIS II (LIS变形)的更多相关文章

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

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

  2. HDU5087——Revenge of LIS II(BestCoder Round #16)

    Revenge of LIS II Problem DescriptionIn computer science, the longest increasing subsequence problem ...

  3. hdu5087——Revenge of LIS II

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

  4. HDOJ 5087 Revenge of LIS II DP

    DP的时候记录下能否够从两个位置转移过来. ... Revenge of LIS II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: ...

  5. hdoj 5087 Revenge of LIS II 【第二长单调递增子】

    称号:hdoj 5087 Revenge of LIS II 题意:非常easy,给你一个序列,让你求第二长单调递增子序列. 分析:事实上非常easy.不知道比赛的时候为什么那么多了判掉了. 我们用O ...

  6. 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 ...

  7. HDOJ 5088 Revenge of Nim II 位运算

    位运算.. .. Revenge of Nim II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  8. hdu5087 Revenge of LIS II (dp)

    只要理解了LIS,这道题稍微搞一下就行了. 求LIS(最长上升子序列)有两种方法: 1.O(n^2)的算法:设dp[i]为以a[i]结尾的最长上升子序列的长度.dp[i]最少也得是1,就初始化为1,则 ...

  9. HDU 5078 Revenge of LIS II(dp LIS)

    Problem Description In computer science, the longest increasing subsequence problem is to find a sub ...

随机推荐

  1. thinkphp模型创建

  2. 详解MySQL大表优化方案

    单表优化 除非单表数据未来会一直不断上涨,否则不要一开始就考虑拆分,拆分会带来逻辑.部署.运维的各种复杂度,一般以整型值为主的表在千万级以下,字符串为主的表在五百万以下是没有太大问题的.而事实上很多时 ...

  3. Codeforces 946D Timetable(预处理+分组背包)

    题目链接:http://codeforces.com/problemset/problem/946/D 题目大意:有n个字符串,代表n天的课表,1表示这个时间要上课,0表示不要上课,一天在学校时间为第 ...

  4. (六)MyBatis杂项

    第一节:处理CLOB.BLOB类型数据 第二节:传入多个输入参数 第三节:MyBatis分页 1,逻辑分页 2,物理分页 MyBatis默认情况下,MyBatis启用一级缓存,即同一个SqlSessi ...

  5. 宝塔Linux常用命令

    https://www.bt.cn/bbs/thread-1186-1-1.html 2017年3月8日发布全新架构的宝塔Linux 面板3.1Beta版,到现在的5.2.0正式版,历经100多天打磨 ...

  6. more命令 less命令

    more命令是一个基于vi编辑器文本过滤器,它以全屏幕的方式按页显示文本文件的内容,支持vi中的关键字定位操作.more名单中内置了若干快捷键,常用的有H(获得帮助信息),Enter(向下翻滚一行), ...

  7. Android Activity、Service、BroadcastReceiver 的生命周期

    Activity.Service.BroadcastReceiver这三个组建是Android开发中最常使用到的组件,在它们的生命周期的各个阶段我们需要针对性的做些事情,了解这些组件的生命周期有利于我 ...

  8. day1作业:编写登录窗口一个文件实现

    思路: 1.参考模型,这个作业我参考了linux的登录认证流程以及结合网上银行支付宝等锁定规则: 1)认证流程参考的是Linux的登录:当你输入完用户名密码后再验证用户名是否存在用户是否被锁定,然后在 ...

  9. 支持多个title,解决主副标题分别对齐

  10. Rookey.Frame之实体FluentValidation验证

    昨天给大家介绍了Rookey.Frame框架的实体设计,今天继续跟大家分享实体的FluentValidation验证,在Rookey.Frame框架中可以设置多种验证方式:FluentValidati ...