HDU 1950 bridging signals "longest ascending sequence"

Source: Internet
Author: User

Problem-Solving Ideas: The description given by the topic is a method to find the longest ascending sub-sequence to find the longest common sub-sequence is the longest ascending subsequence by the number an and its ascending order of an.

But this problem is timed out with this method, and the optimization with the scrolling array also times out,

Here is an algorithm for finding Lis on the Internet

Suppose you want to find the sequence of the longest ascending subsequence is a[n], and then find the increment subsequence to put into array B.

(1) When traversing to the first element of array A, the element is placed into the B array, and the elements that are traversed later are compared to the elements that have been placed in the B array;

(2) If it is larger than each element in the B array, the element is inserted into the last element of the B array, and the length of the b array is added 1;

(3) If it is smaller than the last element in the B array, the binary method is used to find the first smallest element larger than the element, and then replace it.

In this process, only the two steps are repeated, and the length of the last B array is the longest ascending subsequence length.

For example, the sample gives 4 2 6 3 1 5

So

4//

2//Replace with 2 4

2 6//Join 6

2 3//with 3 replacement 6

1 3//with 1 replacement 2

1 3 5//Join 5

Note that the number in the last obtained array of A is 1 3 5

And in fact we're asking for the longest ascent sequence of 2 3 5 but we just need the length, so it doesn't affect

Bridging signals

time Limit : 5000/1000 MS (java/others)     Memory limit:65536/32768 K (java/others) total submission (s): 736 &N bsp;  Accepted Submission (s): 486

Problem Description ' Oh no, they ' ve done it again ', cries the chief designer at the Waferland chip factory. Once more The routing designers has screwed up completely, making the signals on the chip connecting the ports of the Ctional blocks cross each of the other and the place. At this late stage of the process, it's too expensive to redo the routing. Instead, the engineers has to bridge the signals, using the third dimension, so, no, and cross signals. However, bridging is a complicated operation, and thus it's desirable to bridge as few signals as possible. The call for a computer program This finds the maximum number of signals which may is connected on the silicon surface wit Hout rossing each and imminent. Bearing in mind that there is housands of signal ports at the boundary of a functional block, the problem asks quite a Lot of the programmer. Is you up to the task? Figure 1. To the left:the, blocks ' ports and their signal mapping (4,2,6,3,1,5). to the RighT:at Most three signals is routed on the silicon surface without crossing. The dashed signals must be bridged.
A Typical situation is schematically depicted in Figure 1. The ports of the functional blocks is numbered from 1 to p and from top to bottom. The signal mapping is described by a permutation of the numbers 1 to p in the form of a list of P unique numbers in the RA Nge 1 to P, in which the i:th number pecifies which ports on the right side should is connected to the i:th port on the Lef T side. Signals cross if and only if the straight lines connecting the and the ports of each pair Do. inputon the first line Of the input, there is a single positive an integer n, telling the number of the test scenarios to follow. Each test scenario begins with a line containing a single positive integer p<40000, and the number of ports on the both Func tional blocks. Then follow P lines, describing the signal mapping:on the i:th line is the port number of the "The Block on the" right side WHI CH should is connected to the i:th port of the block on the left side.  outputfor Each test scenario, output one linecontaining the maximum number of signals which May is routed on the silicon surface without crossing each Other. samp Le input4642631510234567891018876543219589231746 sample output3914 
#include <stdio.h>int b[500010],f[500010];int bserch (int f[],int n,int v) {    int x,y,m;    X=1;    Y=n;    while (x<=y)    {        m= (x+y)/2;        if (V>=f[m])        x=m+1;        else        y=m-1;    }    return x;} int main () {    int i, n,len,ncase,tmp,x,y;    scanf ("%d", &ncase);    while (ncase--)    {    scanf ("%d", &n);        for (i=1;i<=n;i++)        scanf ("%d", &b[i]);        Len=1;        F[1]=B[1];                for (i=2;i<=n;i++)        {            if (B[i]>=f[len])            {                len++;                F[len]=b[i];            }            else            {                tmp=bserch (f,len,b[i]);                F[tmp]=b[i];                         }        }        printf ("%d\n", Len);}               }

  

HDU 1950 bridging signals "longest ascending sequence"

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.