Nyoj 214 Monotone Increment subsequence (ii)

Source: Internet
Author: User

#include <stdio.h>
#include <string.h>
const int maxn=100001;
int DP[MAXN],A[MAXN];
int binary_search (int len,int k)
{
Find a location that is smaller or equal than the first dp[i]
int start,end,mid;
Start=1;
End=len;
while (Start<=end)
{
Mid= (start+end) >>1;
if (K==dp[mid])
return mid;
if (K>dp[mid])
start=mid+1;
Else
End=mid-1;
}
return start;
}
int main ()
{
int N,i,t,len;
while (scanf ("%d", &n)!=eof)
{
Memset (Dp,0,sizeof (DP));
for (i=0;i<n;i++)
scanf ("%d", &a[i]);
Len=1;
DP[1]=A[0];
for (i=1;i<n;i++)
{
T=binary_search (Len,a[i]);//Find the location to insert by binary search
Dp[t]=a[i]; Updating the value of a DP
if (T>len)//If the position is inserted at the end, update the maximum length
len=t;
}
printf ("%d\n", Len);
}
}

Nyoj 214 Monotone Increment subsequence (ii)

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.