给n个数,求出最长非下降序列。
Input
第一行一个整数n(1≤n≤105)
第二行n个整数ai(1≤ai≤109)
Output
输出一个整数表示最长非下降序列的长度。
Sample Input
Raw
5
1 2 3 4 5
5
1 1 1 1 1
Sample Output
Raw
5
5
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string.h>
using namespace std;
const int maxn=1e5+5;
#define me(x) memset(x,0,sizeof(x));
int dp[maxn]={0};
int a[maxn];
int b[maxn];
int main()
{
int n;
while(cin>>n)
{
me(dp);
for (int i = 1; i <= n; i++)
cin >> a[i];
int cnt = 1;
b[1] = a[1];
for (int i = 2; i <= n; i++)
{
if (a[i] >= b[cnt])
b[++cnt] = a[i];
else {
int j = upper_bound(b + 1, b + 1 + cnt, a[i]) - b;
b[j] = a[i];
}
}
cout << cnt << endl;
}
return 0;
}