{Poj} {3903} {Stock Exchange} {nlogn longest ascending subsequence}

Source: Internet
Author: User

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 ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.