简单dp
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const int maxn=1000; int a[maxn]; int b[maxn]; int n; int ans; int main() { while(~scanf("%d",&n)){ for(int i=1;i<=n;i++) scanf("%d",&a[i]); ans=1; for(int i=1;i<=n;i++) b[i]=99999; for(int i=1;i<=n;i++) { int pos=ans+1; int tmp; for(int j=1;j<=ans;j++) { if(b[j]>=a[i]) { if(pos==ans+1) { pos=j; tmp=b[j]; } else { if(b[j]<tmp) { tmp=b[j]; pos=j; } } } } if(pos==ans+1) ans++; b[pos]=a[i]; } printf("%d ",ans); } return 0; }