#include "iostream"
#include "vector"
#include "algorithm"
using namespace std;
int comp(const int &a,const int &b){
return a < b;
}
int main(){
int n,m;
int i, j;
int maxscore;
vector<int> a;
vector<int> system;
int count = 1;
vector<int>::iterator location;
while(scanf("%d",&n) != EOF){
for ( i = 0; i < n; i++){
scanf("%d",&m);
a.push_back(m);
}
system.push_back(a[0]);
for (vector<int>::iterator it = a.begin(); it != a.end(); it++){
sort(system.begin(),system.end(),comp);
location = lower_bound(system.begin(),system.end(),*it);//lower_bound()在first和last中的前闭后开区间进行二分查找
if(location == system.end()){
count++;
system.push_back(*it);
}
else *location = *it;
}
printf("%d\n",count);
a.clear();
system.clear();
count = 1;
}
return 0;
}
本题我使用了两个vector进行排列,a为存储原始数据,system代表子序列,只要每次看是否在子序列中,如果在,就更新子序列,并排序,如果不在,就加入子序列中,代表新的系统。
一个序列中,最长上升子序列的长度就是不下降子序列的个数。