//The fastest ascending sub-sequence of the fastest algorithm, non-dynamic programming, the use of two points of thought, and the idea of the stack,//with each number to the stack top elements compared, if larger than the top of the stack, then into the stack, or use a binary search, find out the first number larger than this number to replace#include <iostream>#include<cstring>#include<algorithm>#include<cstdio>#include<cstdlib>#include<cmath>using namespacestd;intMain () {inttemp, tail; intN; intstack[1001]; scanf ("%d", &N); Tail=0; stack[0] = -1; for(inti =1; I <= N; i++) {scanf ("%d", &temp); if(Temp >Stack[tail]) stack[++tail] = temp;//into the stack Else { intL =1, r =tail; intmid; while(L <= R)//two points{mid= (L + r)/2; if(Temp >Stack[mid]) L= Mid +1; ElseR = Mid-1; } Stack[l]=temp; }} printf ("%d", tail); return 0;}
O (NLOGN) algorithm, longest ascending subsequence, non-motion gauge