Monotonic incrementing subsequence (ii) Time Limit: 1000 MS | memory limit: 65535 KB difficulty: 4
-
Description
-
Given an integer series {a1, a2..., an} (0
For example, the longest monotonic increasing subsequence of 1 9 10 5 11 2 13 is 1 9 10 11 13 with a length of 5.
-
Input
-
Multiple groups of test data (<= 7)
The first row of each group of test data is an integer n, indicating a total of n integers in the sequence, followed by n integers in the next row, indicating all elements in the series. separate each integer with spaces (0 Data ends with EOF.
The input data must be valid (all are int integers )!
-
Output
-
For each group of test data, the length of the output integer sequence is the longest incrementing sub-sequence. Each output occupies one row.
-
Sample Input
-
71 9 10 5 11 2 1322 -1
-
Sample output
-
51
-
AC code:
-
#include
int num[100005],dp[100005];int len;int Binarysearch(int x){int left,right,mid;right=len;left=1;mid=(left+right)/2;while(left<=right){if(x>dp[mid])left=mid+1;else if(x
len)len=j;}printf("%d\n",len);}return 0;}