【DP】 HDU 5087 Revenge of LIS II
来源:互联网 发布:数据库表结构设计 viso 编辑:程序博客网 时间:2024/05/23 19:23
求第二大的LIS
每种情况都要考虑到。。
#include <cstdio>#include <cstring>#include <cstdlib>#include <string>#include <iostream>#include <algorithm>#include <sstream>#include <cmath>using namespace std;#include <queue>#include <stack>#include <vector>#include <deque>#define cler(arr, val) memset(arr, val, sizeof(arr))typedef long long LL;const int MAXN = 102000;const int MAXM = 6000010;const int INF = 0x3f3f3f3f;const int mod = 1000000007;LL num[1400],dp[2][1555];int main(){#ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout);#endif LL n,t; cin>>t; while(t--) { cin>>n; memset(dp,0,sizeof(dp)); memset(num,0,sizeof(num)); for(int i=1; i<=n; i++) { scanf("%I64d",&num[i]); dp[0][i]=1; } LL maxx=1,ans=0; for(int i=2; i<=n; i++) { for(int j=1; j<i; j++) { if(num[i]>num[j]) { if(dp[0][i]<dp[0][j]+1){ dp[1][i]=dp[0][i]; dp[0][i]=dp[0][j]+1; } else if(dp[1][i]<dp[0][j]+1) dp[1][i]=dp[0][j]+1; if (dp[0][i]<dp[1][j]+1){ dp[1][i]=dp[0][i]; dp[0][i]=dp[1][j]+1; } else if (dp[1][i]<dp[1][j]+1) dp[1][i]=dp[1][j]+1; } } if(dp[0][i]==maxx) ans=max(dp[0][i],ans); else { ans=max(dp[1][i],ans); maxx=max(maxx,dp[0][i]); } } cout<<ans<<endl; } return 0;}
0 0
- hdu 5087 Revenge of LIS II dp
- 【DP】 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 5087 Revenge of LIS II(LIS,思路)
- hdu 5087 Revenge of LIS II | dp 次长上升子序列
- hdu 5087 Revenge of LIS II 题解(DP) BestCoder Round #16 1002
- HDU 5087 Revenge of LIS II(次长上升子序列)
- hdu 5087 Revenge of LIS II(BestCoder Round #16)
- hdu 5087 Revenge of LIS II lcs变形
- linux profile of env
- 我所能体会的互联网思维
- python 基于web脚本编程--urlparse
- 算法(一)选择排序--蛮力算法的一种
- springmvc 中遇到的乱码问题解决方式
- 【DP】 HDU 5087 Revenge of LIS II
- 动态规划第五讲——leetcode上的题目动态规划汇总(上)
- iOS缓存方案
- function template application in class
- 动态规划第六讲——leetcode上的动态规划汇总(下)
- SQL Server 触发器
- 【算法】【转】KMP算法详解
- 【BZOJ】【P2096】【Poi2010】【Pilots】【题解】【二分+单调队列】
- NIO与传统IO的区别--通熟易懂,很经典