string:
stack[0]=""; top=0; for(int i=1;i<=n;i++){ cin>>a[i]; if(a[i].find(stack[top])==0){ stack[++top]=a[i]; } else{ int l=1,r=top; while(l<=r){ int mid=(l+r)/2; if(a[i].find(stack[mid])==0) l=mid+1; else r=mid-1; } stack[l]=a[i]; } ans=max(ans,top); }
int同理,改为a[i]>(=)stack[top/mid]即可