解法一:(利用vector)
#include
#include
#include
#include
using namespace std;
int main()
{
int N;
cin>>N;
vector v;
v.push_back(N+10);
for(int i=0;i<N;i++)
{
int x;
cin>>x;
if(x>v.back())
{
v.push_back(x);
}
else
{
auto it =upper_bound(v.begin(),v.end(),x);
*it = x;
}
}
cout<<v.size();
return 0;
}
解法二(利用结构体)
#include
using namespace std;
typedef struct
{
int data[100];
int length;
}St;
int main()
{
St b[100];
long long n;
int i,a[100000],k=0,j=0,flog=0;
cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i];
};
b[k].data[j]=a[0];
b[k].length=1;
for(i=1;i<n;i++)
{
flog=0;
for(int q=0;q<=k;q++)
{
if(a[i]<b[q].data[b[q].length-1])
{
b[q].data[b[q].length]=a[i];
b[q].length+=1;
flog = 1;
//cout<<endl;
break;
}
}
if(flog == 1)
{
flog = 0;
continue;
}
if(flog == 0)
{
++k;
j=0;
b[k].data[j]=a[i];
b[k].length+=1;
}
}
/*for(i=0;i<=k;i++)
{
for(int t =0;t<b[i].length;t++)
{
cout<<b[i].data[t]<<" ";
}
cout<<endl;
} */
cout<<k+1;
return 0;
}