Nyoj 214 Monotone Increment subsequence (ii)

Source: Internet
Author: User

Monotone increment subsequence (ii) time limit:MS | Memory limit:65535 KB Difficulty:4
Describe

Given an integer sequence {a1, a2..., an} (0<n<=100000), find out the monotone increment of the oldest eldest and calculate its length.

For example: 1 9 10 5 11 2 13 The longest monotonically incrementing subsequence is 1 9 10 11 13 with a length of 5.

Input
There are multiple sets of test data (<=7)
The first line of each set of test data is an integer n indicating that the sequence has n integers, followed by n integers in the next row, representing all the elements in the sequence. The middle of each shape number is separated by a space (0<n<=100000).
The data ends with EOF.
The input data is guaranteed to be legal (all int integers)!
Output
The length of the longest increment subsequence for each set of test data output shaping sequences, one row per output.
Sample input
71 9 10 5 11 2 1322-1
Sample output
51

1#include <iostream>2#include <cstdio>3 Const intMAX =100000+Ten;4 using namespacestd;5 intA[max], Dp[max];6 7 intBinary_search (intDigitintlength)8 {9     intleft=1, right =Length,mid;TenMid= (Right+left)/2; One      while(left<=Right ) A     { -         if(digit==Dp[mid]) -             returnmid; the         if(digit>Dp[mid]) -Left=mid+1; -         Else -right=mid-1; +Mid= (Right+left)/2; -     } +     returnLeft ; A } at intMain () - { -     intn,i,j,k; -      while(~SCANF ("%d", &N)) -     { -          for(i=0; i<n;i++) inscanf"%d", &a[i]); -         intlen=1; todp[1]=a[0]; +          for(i=1; i<n;i++) -         { thej=Binary_search (A[i],len); *dp[j]=A[i]; $             if(j>len)Panax Notoginsenglen=J; -         } theprintf"%d\n", Len); +     } A     return 0; the}

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.