HDU 1950 bridging signals-binary method for longest ascending subsequence

Source: Internet
Author: User
/*** Minimum last element of the ascending subsequence with the storage length of P [I] X can be introduced. The element divisions in P [I] are arranged in ascending order, * Because a sequence with the length of I can be found in the sequence with the length of I-1, the last element of the sequence with the length of I-1 must be smaller than the last element of the sequence with the length of I, ascending subsequence? * If P [I-1] is larger than P [I], the last element of the sequence whose length is I-1 above can update it * if the current element is largest, the length is increased. * Otherwise, you can find a new one, find the maximum number of lines that can be left * in the order of one side, and find the length of the longest ascending subsequence. Common methods may time out, So binary */# include <stdio. h> int d [40010], p [40010], L; int main () {int t, n, I, STA, end, mid; scanf ("% d ", & T); While (t --) {scanf ("% d", & N); for (I = 1; I <= N; I ++) scanf ("% d", & D [I]); P [1] = d [1]; L = 1; for (I = 2; I <= N; I ++) {sta = 1; end = L + 1; while (STA <End) {mid = (STA + end)/2; if (d [I] <= P [Mid]) End = mid; elsesta = Mid + 1;} p [end] = d [I]; if (END = L + 1) l ++;} printf ("% d \ n", L);} 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.