问题描述
B君的希望后续,B君想爬更多的山,请帮助他解决。(cin,cout很坑)
输入格式
输入第一行为num(1~1500000)和maxHeight(1~8848),代表山的个数和最大高度
输入第二行有num个整数,代表表上每座山的高度height(1~maxHeight)
输出格式
输出只有一个数,为符合要求的最大爬山数
样例输入
10 10
8 6 8 5 9 5 2 7 3 6 3 4
样例输出
3
样例输入
10 20
8 19 9 10 3 3 15 3 10 6
样例输出
4
数据规模和约定
num(1~1500000),maxHeight(1~8848),height(1~maxHeight),都是正整数
#include<iostream>
#include<algorithm>
using namespace std;
int dp[1500010],n,a[1500010],len=0;
int main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n;
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++){
int l=0,r=len;
while(l<r){
int mid=l+r+1>>1;
if(a[i]>dp[mid])l=mid;
else r=mid-1;
}
dp[l+1]=a[i];len=max(len,l+1);
}
cout<<len;
return 0;
}