标签:
#include<iostream> #include<cstdio> #define maxn 10010 using namespace std; int a[maxn],f[maxn],pre[maxn]; int main() { freopen("maxxl.in","r",stdin); freopen("maxxl.out","w",stdout); int n,i,j,k; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&a[i]); f[i]=1; pre[i]=i; } for(i=1;i<=n;i++) { for(j=i+1;j<=n;j++) { if(a[j]>=a[i]&&f[j]<=f[i]+1) { if(f[j]<f[i]+1) { f[j]=f[i]+1; pre[j]=i; } else pre[j]=min(pre[j],i); } } } int maxx=0; for(i=1;i<=n;i++) if(f[i]>maxx) { k=i; maxx=f[i]; } printf("%d\n",maxx); int b[maxn],l=0; while(k!=pre[k]) { b[++l]=a[k]; k=pre[k]; } b[++l]=a[k]; for(i=maxx;i>=1;i--) printf("%d ",b[i]); return 0; }
标签:
原文地址:http://www.cnblogs.com/dingmenghao/p/5563223.html