#include <iostream>
using namespace std;
int quick_lds( int n, int a[], int d[] )
{
int ans = 0;
for(int i=1; i<=n; ++i)
{
int j = 1;
int k = ans;
while( j <= k )
{
int m = ( j + k ) >> 1;
if( d[m] < a[i] ) j = m + 1;
else k = m - 1;
}
if( j > ans ) ++ans;
d[j] = a[i];
}
return ans;
}
void main()
{
int n = 0, max_num = 0;
int i, j;
cout << "Please input the number of the array element:" << endl;
cin >> n;
if (n < 1)
return ;
else cout << "Please input "<< n << " integers:"<< endl;
int * a = new int [n];
int * record = new int [n];
for (i = 0; i < n; ++i)
{
cin >> a[i];
record[i] = 1;
}
/*
for (i = n - 2; i >= 0; --i)
{
for (j = i + 1; j < n; ++j)
{
if (record[i] < record[j] + 1 && a[i] < a[j])
record[i] = record[j] + 1;
}
}
for (i = 0; i < n; ++i)
{
if (max_num < record[i])
max_num = record[i];
}
cout<<"The answer is: "<<max_num<<endl;*/
cout<<endl<<quick_lds(n,a, record)<<endl;
delete[] record;
record = NULL;
delete[] a;
a = NULL;
}