Zoj 1986 Maximum ascending order number

Source: Internet
Author: User

////////////////////////////////////
// Maximum ascending order
// Use the DP + binary method
// If the conventional method is used, the time of N ^ 2 is used, and the time after the second is used is reduced to nlogn.

 

// This kind of bipartite method is clever. First get an array st [], read a [I] each time, and find the last st [k] That is smaller than it in St [].
// Replace s [k] with a [I]. When K is smaller than Len, this replacement will not change the maximum number of the longest chain; when K is Len, the maximum number of chains
// It is changed to a smaller number A [I], which does not affect the extension of the chain and is easier to lengthen. When k = Len + 1, simply lengthen one a [I]
// However, this method cannot output the oldest sequence.

# Include <iostream>
Using namespace STD;
Unsigned int A [40005];
Unsigned int st [40005];

Int main ()
{
Unsigned int I, n, num, Len, left, right, mid;
Cin> N;
While (n --)
{
Cin> num;
For (I = 0; I <num; I ++)
Cin> A [I];

St [0] = 0;
St [1] = A [0];
Len = 1;
For (I = 1; I <num; I ++)
{
Left = 0; Right = Len;
While (left <= right)
{
Mid = (left + right)/2;
If (ST [Mid] <= A [I])
Left = Mid + 1; // set left to the next K smaller than a [I]
Else
Right = mid-1;
}
St [left] = A [I];
If (left> Len)
Len ++;
}
Cout <Len <Endl;
}
Return 0;
}

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.