ZOJ 1986 最长上升子序列
比赛时看着题的太长了,加上又全是英文(英语不太好T_T.....)题意没理解,就放弃了,后来听说是求他的最长上升子序列,我勒个去啊!
一个简单的DP搞这么麻烦的题目。。。。要用O(n*logn)方法过。。。。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #define N 40005 5 6 int stack[N]; 7 int main() 8 { 9 int i,temp,ncases; 10 int top,n,low,mid,high; 11 12 scanf("%d",&ncases); 13 while( ncases-- ) 14 { 15 top = 0; 16 stack[0] = -1; 17 scanf("%d",&n); 18 while( n-- ) 19 { 20 scanf("%d",&temp); 21 if(temp > stack[top]) 22 { 23 stack[++top] = temp; 24 } 25 else 26 { 27 low = 1, high = top; 28 while(low <= high) 29 { 30 mid = (low + high)/2; 31 if(temp > stack[mid]) 32 low = mid+1; 33 else 34 high = mid-1; 35 } 36 stack[low] = temp; 37 } 38 } 39 40 printf("%d\n",top); 41 } 42 system("pause"); 43 return 0; 44 }