LIS (最长上升子序列)
2016-08-16 19:58
330 查看
LIS两种写法
O(n^2)
dp[i]表示以a[i]结尾的为LIS长度
View Code
O(n^2)
dp[i]表示以a[i]结尾的为LIS长度
//#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <vector> #include <cmath> #include <ctime> #include <list> #include <set> #include <map> using namespace std; typedef long long LL; typedef pair <int, int> P; const int N = 1e5 + 5; int dp , a , inf = 1e6; int main() { int n; while(~scanf("%d", &n)) { for(int i = 0; i <= n + 1; ++i) dp[i] = inf; for(int i = 1; i <= n; ++i) { scanf("%d", a + i); *lower_bound(dp, dp + n, a[i]) = a[i]; } printf("%d\n", lower_bound(dp, dp + n, inf) - dp); } return 0; }
View Code
相关文章推荐
- 【UVA】10534 - Wavio Sequence(LIS最长上升子序列)
- LIS(最长上升子序列)
- uvaoj 103 Stacking Boxes 最长上升子序列LIS
- 动态规划-最长上升子序列(LIS)
- 最长上升子序列(LIS)算法
- Stock Exchange(最长上升子序列LIS)
- HDU 1025 Constructing Roads In JGShining's Kingdom(DP,LIS最长上升子序列)
- HDU 1025 Constructing Roads In JGShining's Kingdom (简单dp, 最长上升子序列LIS)
- LIS(最长上升子序列)
- 最长上升子序列LIS
- 最长上升子序列LIS
- 动态规划-最长上升子序列(LIS)
- 【转载】最长上升子序列(LIS)长度的O(nlogn)算法
- BZOJ 3173: [Tjoi2013]最长上升子序列( BST + LIS )
- Stock Exchange(LIS最长上升子序列问题)
- 最长上升子序列LIS
- 【转载】动态规划--最长上升子序列(LIS)
- 最长上升子序列(LIS)算法分析
- SPOJ 3937 - Wooden Sticks 最长上升子序列LIS
- 最长上升子序列LIS