Question:Calculates the longest ascending subsequence, n = 100000
Ideas:O (N ^ 2) definitely times out .... Use greedy ideas to find answers. The stack is used to check the stack for each input data, and the minimum and maximum data size is replaced by the binary search. The stack is better. This question is really good and has a good idea.
# Include <iostream> # include <string> # include <cstring> # include <cstdio> # include <algorithm> # include <memory> # include <cmath> # include <bitset> # include <queue> # include <vector> # include <stack> using namespace STD; # define CLR (x, y) memset (X, Y, sizeof (x) # define min (M, V) (m) <(v )? (M) :( v) # define max (M, V) (m)> (v )? (M) :( v) # define ABS (x)> 0? (X):-(x) # define rep (I, x, y) for (I = x; I <Y; ++ I) const int maxn = 110000; int n, m; int Len; int val; int s [maxn]; int BF (INT cur) {int low, high, mid; int pre; Low = 0; high = len-1; while (low <= high) {mid = (low + high)> 1; if (s [Mid] <cur) {LOW = Mid + 1 ;} else if (s [Mid]> cur) {high = mid-1;} else return mid;} return low;} void solve () {While (scanf ("% d", & N )! = EOF) {Len = 0; For (INT I = 0; I <n; ++ I) {scanf ("% d", & Val ); if (LEN = 0 | s [len-1] <Val) {s [Len] = val; + + Len;} else {int F = BF (VAL ); s [f] = Val ;}} printf ("% d \ n", Len) ;}int main () {solve (); Return 0 ;}