标签:
一:
很容易想到的 DP的O(N^2)的复杂度
#pragma comment(linker,"/STACK:102400000,102400000") #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype> #include <cmath> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <map> using namespace std; #define clc(a, b) memset(a, b, sizeof(a)) const int inf = 0x3f; const int INF = 0x3f3f3f3f; const int maxn = 1000; int n, a[maxn], dp[maxn]; int LIS() { int i, j, k = 0; for(i = 0; i < n; i++) { dp[i] = 1; for(j = 0; j < i; j++) { if(a[i] > a[j] && dp[i] < dp[j] + 1) { dp[i] = dp[j] + 1; } } k = dp[i] > k ? dp[i] : k; } return k; } int main() { while(~scanf("%d", &n)) { clc(dp, 0); for(int i = 0; i < n; i++) scanf("%d", &a[i]); printf("LIS = "); printf("%d\n", LIS()); } }
二: 扩展升级版, 求定长的上升子序列个数
标签:
原文地址:http://www.cnblogs.com/tenlee/p/4539494.html