#include<bits/stdc++.h>
using namespace std;
const long long maxx=0x3f3f3f3f3f3f3f3f;
const long long minn=0xc0c0c0c0c0c0c0c0;
const double pi = 4.0*atan(1.0);
#define int long long
#define f(i,n,m) for(long long i=n;i<=m;++i)
#define unf(i,n,m) for(long long i=n;i>=m;--i)
#define kong NULL
#define debug cout<<"sss"<<endl;
inline int readint(){int x = 0, f = 1;char ch = getchar();while(ch < '0' || ch > '9'){if (ch == '-')f = -1;ch = getchar();}while(ch >= '0' && ch <= '9'){x = (x<<1) + (x<<3) + (ch^48);ch = getchar();}return x * f;}
inline string readstr(){char ch = getchar();string st1 = "";while (!((ch >= 'a') && (ch <= 'z')))ch = getchar();while ((ch >= 'a') && (ch <= 'z'))st1 += ch, ch = getchar();return st1;}
int n;
int a;
int dp[50010];
void solve() {
cin>>n;
int t=0;
f(i,1,n){
cin>>a;
if(i==1||a>dp[t]){
t++;dp[t]=a;
}
else {
*upper_bound(dp+1,dp+t+1,a)=a;
}
}
cout<<t<<endl;
}
signed main( )
{
ios::sync_with_stdio(false);
solve();
return 0;
}
总结:
设dp【】为取出来的那个数列,遇到一个数字进去判断该数字是否大于dp当前最大的那个数字(应为dp是连续上升子序列所以是单调增的,最大的就是dp【t】,t为其当前长度)如果大于,那么t++,吧遇到的数字放入dp【t++】中,反之则对该dp数列进行优化(即用二分的方式找到dp数列中第一个大于遇到数字的数,用遇到的数字替换他)
ios::sync_with_stdio(false);
solve();
return 0;
}