Information
- ID
- 1229
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 8
- Tags
- # Submissions
- 29
- Accepted
- 5
- Uploaded By
#include <iostream>
#include <cmath>
#include <algorithm>
#define QAQ ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
const int N=100005;
using namespace std;
int n,h[N],dp1[N],cnt=0;//dp1记录最后一个上升的数,cnt记录数量
int find(int l,int r,int x)//用二分查找从左找到dp1中第一个大于x的数
{
while(l<r)
{
int mid=(l+r)/2;
if(dp1[mid]>=x)
r=mid;
else
l=mid+1;
}
return l;
}
int main(){
QAQ;
//求最长上升子序列
cin>>n;
dp1[0]=-1e9;
for(int i=1;i<=n;i++)
{
cin>>h[i];
if(h[i]>dp1[cnt])//如果上升,则记录dp1;
{
dp1[++cnt]=h[i];
// cout<<cnt<<' ';
}
else
{
int j=find(1,cnt,h[i]);
dp1[j]=h[i];
// cout<<j<<'|';
}
}
cout<<cnt;
return 0;
}
By signing up a 追梦算法网 universal account, you can submit code and join discussions in all online judging services provided by us.