http://acm.split.hdu.edu.cn/showproblem.php?pid=1950
题意:求最长上升(不连续or连续)子序列
推荐博客链接:
http://blog.csdn.net/sinat_30062549/article/details/47197073
#include <iostream> #include <stdio.h> #include <string.h> #include <string> #include <vector> #include <algorithm> #include <map> #include <queue> #include <stack> #include <math.h> using namespace std; #define INF 0x3f3f3f3f const int maxn = 510000; typedef long long LL; int a[maxn], s[maxn]; int main() { int T, n; scanf("%d", &T); while(T --) { scanf("%d", &n); for(int i=1; i<=n; i++) scanf("%d", &a[i]); int len = 0; memset(s, 0, sizeof(s)); for(int i=1; i<=n; i++) { if(a[i]>=s[len]) { s[++len]=a[i]; continue; } int pos = upper_bound(s, s+len, a[i])-s;///找出s数组中比a[i]大的数字的下标 s[pos] = a[i]; } printf("%d ", len); } return 0; }