最长上升子序列和找有多少个递减的其实是一个事情;
如8 4 2 5 3 9 1 6 7这个序列,找最长上升子序列,
以下代码的过程就是,8 4 2 1都在N[0]那里变化,5 3在N[1]那里变化
9 6在N[2]那里变化 7在N[3]那里变化,所以最后的数组是1 3 6 7,长度为4;
#include <iostream>
#include <string>
#include <cstring>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define ll long long
using namespace std;
#define MAX 0x3f3f3f3f
int N[100005];
int main()
{
int n, t;
cin >> n;
memset(N, MAX, sizeof(N));
for (int i = 0; i < n; i++)
{
int m;
cin >> m; //lower是找数组内第一个大于等于m的那个数的地址,减去
t = lower_bound(N, N + n, m) - N;//首地址就是那个i了;
N[t] = m;
}
cout << lower_bound(N, N + n, MAX) - N;
return 0;
}