poj 1631 简单的LIS问题
来源:互联网 发布:剑三纯阳捏脸数据女 编辑:程序博客网 时间:2024/06/08 11:54
Bridging signals
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 14426 Accepted: 7807
Description
'Oh no, they've done it again', cries the chief designer at the Waferland chip factory. Once more the routing designers have screwed up completely, making the signals on the chip connecting the ports of two functional blocks cross each other all over the place. At this late stage of the process, it is too expensive to redo the routing. Instead, the engineers have to bridge the signals, using the third dimension, so that no two signals cross. However, bridging is a complicated operation, and thus it is desirable to bridge as few signals as possible. The call for a computer program that finds the maximum number of signals which may be connected on the silicon surface without crossing each other, is imminent. Bearing in mind that there may be thousands of signal ports at the boundary of a functional block, the problem asks quite a lot of the programmer. Are you up to the task?
A typical situation is schematically depicted in figure 1. The ports of the two functional blocks are numbered from 1 to p, 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 range 1 to p, in which the i:th number specifies which port on the right side should be connected to the i:th port on the left side.Two signals cross if and only if the straight lines connecting the two ports of each pair do.
A typical situation is schematically depicted in figure 1. The ports of the two functional blocks are numbered from 1 to p, 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 range 1 to p, in which the i:th number specifies which port on the right side should be connected to the i:th port on the left side.Two signals cross if and only if the straight lines connecting the two ports of each pair do.
Input
On the first line of the input, there is a single positive integer n, telling the number of test scenarios to follow. Each test scenario begins with a line containing a single positive integer p < 40000, the number of ports on the two functional blocks. Then follow p lines, describing the signal mapping:On the i:th line is the port number of the block on the right side which should be connected to the i:th port of the block on the left side.
Output
For each test scenario, output one line containing the maximum number of signals which may be routed on the silicon surface without crossing each other.
Sample Input
4642631510234567891018876543219589231746
Sample Output
3914
Source
Northwestern Europe 2003
方法:直接用LIS的模板,注意数据较大,应用O(nlogn)方法,并注意输入输出的函数
#include <iostream>#include <algorithm>#include <cstdio>using namespace std;#define MAX 100000int n, A[MAX+1], L[MAX+1], T;int lis()//此模板定牢记{ L[0] = A[0]; int length = 1; for(int i=1; i<n; i++) { if(L[length-1] < A[i]) L[length++] = A[i]; else *lower_bound(L, L+length, A[i]) = A[i]; } return length;}int main(){ scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i=0; i<n; i++) { scanf("%d",&A[i]); } printf("%d\n",lis()); } return 0;}
阅读全文
1 0
- poj 1631 简单的LIS问题
- poj 1631 nologn LIS
- poj 1631 LIS nlogn
- (经典)POJ-1631 LIS,偏序问题
- poj 1836(简单DP+两边lis)
- POJ 1631 LIS O(nlogn)
- POJ 1631 Bridging signals(LIS)
- poj 1631 LIS nlogn算法
- poj-1631Bridging signals(LIS)
- POJ 1631 nlogn求LIS
- POJ 1631 LIS 模板题
- POJ 1631(O(nlogn)LIS的2种做法)
- POJ 2533 : Longest Ordered Subsequence - LIS问题
- LIS问题(POJ - 3903 Stock Exchange)
- poj-1836-士兵出列问题-双向LIS
- poj 1903 LIS的Nlogn解法
- POJ 1836 Alignment 变形的LIS
- (经典)POJ-1065 LIS问题,偏序问题
- 关于<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-sc..
- Swagger Adoption
- java查询功能输入**中文字符乱码**问题:
- Less 命令
- MySQL系列课程之三MySQL的登录
- poj 1631 简单的LIS问题
- 从字节码角度分析java泛型数组的问题
- hdu2145
- 两分钟搞定极光推送
- 二、垃圾收集与内存分配策略
- Socket通信
- Hibernate中的query.setFirstResult(),query.setMaxResults();
- 伪分布式Hadoop系统上的wordCount实现命令
- Bsmtp.dll和Bsendm.exe结合发送邮件