- 简单思维题,判断输入数字串顺序。
- 当前数字比所有数字小时需要新开一条路。
- 当前数字不是最小时,插入已知路中末尾比他大最少的数的路。
- 利用set的自动排序来储存所有路中最前最小的数,用lower_bound()二分查找函数找到最优的大于它的数。来保证时间复杂度通过。
c++代码
set<int> p;
void solve()
{
int n;
cin >>n;
int k;
for(int i=1;i<=n;i++){
cin >>k;
set<int>::iterator it=p.lower_bound(k);
if(it!=p.end()){
p.erase(it);
p.insert(k);
}
else p.insert(k);
}
cout <<p.size()<<endl;
}
int main()
{
/*int t;
cin >>t;
while(t--)*/ solve();
return 0;
}