hdu 5087 Revenge of LIS II | dp 次长上升子序列
来源:互联网 发布:阿里云注销备案 编辑:程序博客网 时间:2024/05/21 02:49
题意:
找出次长上升子序列的长度。
思路:
进爷叫我去做一下,没想到被坑了好久。一直在想方法,然后又推翻了= =, 看完题解,之前想的一种思路是对的。可但是,但可是,没去实现 囧。
dp[i]:记录以a[i]结尾的最长上升序列的长度。
cot[i]:记录以a[i]结尾的最长长度的达成方案数。(最大为2即可,再多也没用)
code:
#include <cstdlib>#include <cstdio>#include <iostream>#include <algorithm>using namespace std;const int MAXN = 1005;int a[MAXN], dp[MAXN];int cot[MAXN];int main(){ int T; scanf("%d", &T); while(T--) { int n; scanf("%d", &n); for(int i = 1;i <= n; i++) { scanf("%d" ,&a[i]); } memset(dp, 0, sizeof(dp)); memset(cot, 0, sizeof(cot)); int res = 1; for(int i = 1;i <= n; i++) { dp[i] = 1; cot[i] = 1; for(int j = 1;j < i; j++) { if(a[i] > a[j]) { if(dp[i] == dp[j] + 1) { cot[i] = 2; } else if(dp[i] < dp[j] + 1) { dp[i] = dp[j] + 1; cot[i] = cot[j]; } } } res = max(res, dp[i]); } int cc = 0; for(int i = 1;i <= n; i++) if(dp[i] == res) cc += cot[i]; printf("%d\n", cc >= 2 ? res : res-1); } return 0;}
0 0
- HDU 5087 Revenge of LIS II(次长上升子序列)
- hdu 5087 Revenge of LIS II | dp 次长上升子序列
- HDU5087 - Revenge of LIS II (次长上升子序列)
- hdu 5087 Revenge of LIS II dp
- 【DP】 HDU 5087 Revenge of LIS II
- HDU 5807(Revenge of LIS II)最长不降子序列
- hdu 5087 Revenge of LIS II ( LIS ,第二长子序列)
- HDU 5087 Revenge of LIS II(次大递增子序列)
- Revenge of LIS II (hdu 5087 LIS)
- hdu 5087 Revenge of LIS II(LIS)
- HDOJ 5087 Revenge of LIS II DP
- HDU 5078 Revenge of LIS II(dp LIS)
- HDU - 5087 Revenge of LIS II
- hdu 5087 Revenge of LIS II
- hdu 5087 Revenge of LIS II
- Revenge of LIS II(HDU 5087)
- HDU 5087 Revenge of LIS II
- hdu 5087 Revenge of LIS II(LIS,思路)
- Hdu 5090 Game with Pearls(二分匹配)
- @Response
- LeetCode[Linked List]: Copy List with Random Pointer
- 高仿新闻教程-开源框架的简单实现——网易新闻的标题栏(一)
- 一个可以解析复杂JSON字符串里面值的算法
- hdu 5087 Revenge of LIS II | dp 次长上升子序列
- android中viewpager的学习
- 淘宝爆款女性减肥瘦身产品大集成大排行
- Shell编程学习笔记
- nyoj891(区间上的贪心)
- java基础_IO
- 观察者模式
- hdu1010
- sqlalchemy系列(2) orm相关简易操作