using namespace std; int const N = 1e5+5; int a[N],b[N],sub[N],up[N]; void init(int *t,int n) { for(int i=0;i<=n;i++) t[i]=inf; t[0]=-1; t[1]=a[0]; sub[0]=1; } int main(void) { int max,i,j,n; while(cin>>n) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(sub,0,sizeof(sub)); memset(up,0,sizeof(up)); for(i=0;i<n;i++){ cin>>a[i]; b[i]=a[i]; } sort(b,b+n); int size=unique(b,b+n)-b; for(i=0;i<n;i++) a[i]=lower_bound(b,b+size,a[i])-b+1; cout<<"离散化后的结果"<<endl; for(i=0;i<n;i++) printf("%d%c",a[i],i==n-1?'\n':' '); init(up,n+1); for(i=1;i<n;i++) { //j=lower_bound(up,up+n+1,a[i])-up; j=upper_bound(up,up+n+1,a[i])-up; up[j]=a[i]; sub[i]=j; } for(max=i=0;i<n;i++) if(sub[i]>max) max=sub[i]; cout<<"max sub increase string 's lenth = "<<max<<endl; cout<<"value for all position "<<endl; for(int i=0;i<n;i++){ printf("%d%c",sub[i],i==n-1?'\n':' '); } } return 0; }
|