Problem Description?? Gets an sequence S with n intergers (0 < n <= 100000,0<= S[i] <= 1000000).?? Have a magic so, he can change 0 to any interger (he does not need to change all 0 to the same interger).?? Wants him to find out the length of the longest increasing (strictly) subsequence he can get.
Input The first line contains an Interger t,denoting the number of the the test cases. (T <= 10)
For each case,the first line contains a Interger N,which is the length of the array s.
The next line contains n Intergers separated is a single space, and denote each number in S.
Output for each test case, output one line containing ' case #x: Y ' (without quotes), where x is the ' test Case number (Starti Ng from 1) and Y are the length of the longest increasing subsequence he can get.
Sample Input
2 7 2 0 2 1 2 0 5 6 1 2 3 3 0 0
Sample Output
Case #1:5 case #2:5 Hint in the first case,you can change the second 0 to 3.So the longest increasing subsequence is 0 1 2 3 5.
Author Fzu
Source multi-university Training Contest 4 The longest ascending sub-sequence of the NLOGN algorithm is slightly deformed in relation to the longest ascending subsequence, which means that only a few times (the longest ascending subsequence) are written, and then the direct template deformation can be swept to 0 when the update Each length of the last element, the smaller, how small, the previous length of the end element +1 can then use the Sun record 0 occurrences, reduce the repeat update because 0 can become negative, so initialize d[0] =-inf Not much said, the code is very simple to read the code directly:
#define MEM (a,x) memset (A,x,sizeof (a)) #include <iostream> #include <cstdio> #include <cstring> using
namespace Std;
typedef long Long LL;
const int inf = 1<<29;
/* Description: Longest ascending subsequence definition d[k]: Ascending sequence of length k last element (end element)//Note element in D is monotonically incrementing initialization: len = 1,d[1]=a[1], then for A[i]:
If a[i] > D[len] len++,d[len] = a[i] Else from d[1] to D[len] Find a J
Meet D[J-1]<A[I]<D[J] Update d[j] = a[i] */const int NN = 100007;
int D[NN],A[NN];
int main () {int n;
int kas = 0;
int t;scanf ("%d", &t);
while (t--) {scanf ("%d", &n);
for (int i = 1;i <= n;++i) {scanf ("%d", a+i);
} int len = 1;
D[0] =-inf;
D[1] = a[1];
int sun = 0;
for (int i = 2;i <= n;++i) {if (A[i] > D[len]) {D[++len] = A[i]; } else if (a[i] = = 0)//unique with bare longestAscending sub-sequence different place {for (int j = len;j >= sun;--j) {d[j+1] = d
[J]+1;
} len++;
sun++;
} else {int p = lower_bound (D,d+len,a[i])-D;
D[P] = A[i];
}} printf ("Case #%d:%d\n", ++kas,len);
} return 0;
}