提交时间:2024-03-30 15:37:46
运行 ID: 140486
#include<bits/stdc++.h> using namespace std; const int Maxn=10005; int a[Maxn],f[Maxn]; int n,top=0; int f1(int x) { int l=1,r=top,res=0; while (l<=r) { int mid=(l+r)/2; if (f[mid]>x) { r=mid-1; res=mid; } else { l=mid+1; } } return res; } int main() { cin>>n; for (int i=1;i<=n;i++) { cin>>a[i]; } f[1]=-1e9; for (int i=1;i<=n;i++) { if (a[i]>=f[top]) { f[top+1]=a[i]; top++; } else f[f1(a[i])]=a[i]; } cout<<top<<endl; return 0; }