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)