Bridging signals hdu 1950 (最长上升子序列)

时间:2022-06-19 01:28:39

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 = ;
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=; i<=n; i++)
scanf("%d", &a[i]); int len = ;
memset(s, , sizeof(s)); for(int i=; 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\n", len);
}
return ;
}