zoj1986 bridging signals (DP, longest increment sequence, LIS)

Source: Internet
Author: User

A-bridging Signals
Time limit:2000ms Memory limit:65536kb 64bit IO format:%lld &%llu
Submit

Status

Practice

ZOJ 1986
Description
' Oh No, they ' ve do 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 crossing each and imminent. Bearing in mind that there is thousands 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 ith number specifies which ports on the right side should is connected to the ith port on the left Side. The signals cross if and only if the straight lines connecting the both ports of each pair do.

Input
On the first line of the input, there are a single positive integer n, telling the number of the test scenarios to follow. Each test scenario begins with a line containing a single positive integers p < 40000, the number of ports on the and the FU Nctional blocks. Then follow P lines, describing the signal mapping:

The ith line is the port number of the "the" side which should be connected to the ith port of the block O n the left side.

Output
For each test scenario, output one line containing the maximum number of signals which may be routed on the silicon SURFAC e without crossing each other.

Sample Input
4
6
4
2
6
3
1
5
10
2
3
4
5
6
7
8
9
10
1
8
8
7
6
5
4
3
2
1
9
5
8
9
2
3
1
7
4
6

Sample Output
3
9
1
4

N Test Examples:
Number of samples m per example
。。。。
To find the longest increment sequence, the direct DP. (English is a mishap)

#include <cstdio>#include <cmath>#include <cstring>#include <iostream>#include <algorithm>#include <queue>#include <vector>#include <map>#include <stack>#pragma COMMENT (linker, "/stack:102400000,102400000")#define PI ACOs ( -1.0)#define EPS 1e-6#define INF (1<<24)using namespace STD;intMain () {intT//Freopen ("Test.txt", "R", stdin);    scanf("%d", &t); while(t--) {intNintI,j;intdp[40005];inta[40005];intflag[40005];scanf("%d", &n); for(i=0; i<n;i++)scanf("%d", &a[i]);memset(DP,0,sizeof(DP)); for(i=0; i<n;i++) Flag[i]=inf; for(i=0; i<n;i++) {dp[i]=1; while(A[i]>flag[dp[i]])            {dp[i]++; }if(A[i]<flag[dp[i]]) flag[dp[i]]=a[i]; }intans=0; for(i=0; i<n;i++) Ans=max (Ans,dp[i]);printf("%d\n", ans); }return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

zoj1986 bridging signals (DP, longest increment sequence, LIS)

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.