输入样例:
9
8 4 2 5 3 9 1 6 7
输出样例:
4
Dilworth定理
最少下降序列个数=最长上升序列长度
#include <cstdio>
#include <algorithm>
using namespace std;
const int N=1e5+3;
int a[N];
int main()
{
int n,cnt=0;scanf("%d",&n);
for(int i=1;i<=n;i++)
{
int x;scanf("%d",&x);
int *dex=lower_bound(a,a+cnt,x);
if(dex==a+cnt) ++cnt;
*dex=x;
}
printf("%d\n",cnt);
}