Bridging signals
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 9234   Accepted: 5037

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.

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

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
思路:
最长递增子序列: (二分)代码:
 #include<iostream>
#include<stdio.h>
int arr[]; int search(int a,int b,int n){ //二分
int mid;
while(a<=b){
mid = (a+b)/;
if(n>arr[mid]){
a = mid + ;
}else{
b = mid - ;
}
}
return b;
} int main(){
int t;
scanf("%d",&t);
while(t--){
int n,i;
scanf("%d",&n);
scanf("%d",&arr[]);
int pos=;
for(i=;i<n;i++){
scanf("%d",&arr[pos]);
if(arr[pos]>=arr[pos-]){ //比当前的数大的话插在后面
pos++;
}else{ //如果小的话在前面找到合适的位置插入
int m = search(,pos-,arr[pos]);
arr[m+]=arr[pos];
}
}
printf("%d\n",pos);
}
return ;
}

poj 1631 Bridging signals (二分||DP||最长递增子序列)的更多相关文章

  1. Poj 1631 Bridging signals(二分+DP 解 LIS)

    题意:题目很难懂,题意很简单,求最长递增子序列LIS. 分析:本题的最大数据40000,多个case.用基础的O(N^2)动态规划求解是超时,采用O(n*log2n)的二分查找加速的改进型DP后AC了 ...

  2. Luogu 3402 最长公共子序列(二分,最长递增子序列)

    Luogu 3402 最长公共子序列(二分,最长递增子序列) Description 经过长时间的摸索和练习,DJL终于学会了怎么求LCS.Johann感觉DJL孺子可教,就给他布置了一个课后作业: ...

  3. [DP]最长递增子序列

    #include <iostream> #include <limits.h> #include <vector> #include <algorithm&g ...

  4. HDU-1160-FatMouse's Speed(DP, 最长递增子序列)

    链接: https://vjudge.net/problem/HDU-1160 题意: FatMouse believes that the fatter a mouse is, the faster ...

  5. POJ 1631 Bridging signals DP(最长上升子序列)

    最近一直在做<挑战程序设计竞赛>的练习题,感觉好多经典的题,都值得记录. 题意:给你t组数据,每组数组有n个数字,求每组的最长上升子序列的长度. 思路:由于n最大为40000,所以n*n的 ...

  6. POJ - 1631 Bridging signals(最长上升子序列---LIS)

    题意:左右各n个端口,已知n组线路,要求切除最少的线路,使剩下的线路各不相交,按照左端口递增的顺序输入. 分析: 1.设左端口为l,右端口为r,因为左端口递增输入,l[i] < l[j](i & ...

  7. POJ 1631 Bridging signals (LIS:最长上升子序列)

    题意:给你一个长为n(n<=40000)的整数序列, 要你求出该序列的最长上升子序列LIS. 思路:要求(nlogn)解法 令g[i]==x表示当前遍历到的长度为i的所有最长上升子序列中的最小序 ...

  8. OpenJudge/Poj 1631 Bridging signals

    1.链接地址: http://poj.org/problem?id=1631 http://bailian.openjudge.cn/practice/1631 2.题目: Bridging sign ...

  9. POJ 1631 Bridging signals(LIS O(nlogn)算法)

    Bridging signals Description 'Oh no, they've done it again', cries the chief designer at the Waferla ...

随机推荐

  1. URL格式编码与解码

    char* urlencode(const void* buf, size_t size) { _assert_(buf && size <= MEMMAXSIZ); const ...

  2. PowerDesigner 根据NAME属性自动生成表和列注释(不用写脚本)

    PowerDesigner 11 menu: [Database]->[Database Generation] tab: [Tables & Views]->check tabl ...

  3. Oracle性能调优(AWR)

    一.AWR报告 AWR 是通过对比两次快照(snapshot)收集到的统计信息,来生成报表数据,生成的报表包括多个部分,这点与Statspack生成的报告非常类似.不过AWR在生成报告时,可以选择生成 ...

  4. android之手工建立代码工程

    文件夹及文件架构: AndroidManifest.xml Android.mk res/layout/main.xml res/values/strings.xml src/com/liuzw/he ...

  5. 【Objective-C】0-第一个OC的类

    OC是一门面向对象的语言,因此它也有类.对象.静态\动态方法.成员变量的概念.这讲就来创建第一个OC的类. 一.语法简介 1.类 在Java中,我们用1个.java文件就可以描述清楚一个类:在OC中, ...

  6. C#学习笔记13:静态方法、方法重载和ref、out参数

    静态方法 调用:如果你写的方法和Main()方法在同一个类中,直接写方法名. 如果不在一个类中,需要类名.方法名(); 非静态方法: 调用:创建一个类的对象  对象名.方法名(); Person pe ...

  7. 文件上传~Uploadify上传控件

    对于文件上传来说,有很多种实现方式,如传统的表单方式,现在流行的flash方式,甚至还有纯JS方式,之所以有这些方式来实现文件上传,我想主要原因是因为,传统的上传对于大文件支持不够,因为它是单线程同步 ...

  8. 检测PC端和移动端的方法总结

    正在苦逼的实习中,昨天公司让做一个页面,涉及到检测终端的问题,如果是手机设备,就跳转到指定的网页上,以前写响应式布局只要用@media screen来实现布局的差异化适应,但是现在不仅仅是布局,还要针 ...

  9. NOIP200701

    题是这样的: 试题描述 某小学最近得到了一笔赞助,打算拿出其中一部分为学习成绩优秀的前5名学生发奖学金.期末,每个学生都有3门课的成绩:语文.数学.英语.先按总分从高到低排序,如果两个同学总分相同,再 ...

  10. 374. Guess Number Higher or Lower

    We are playing the Guess Game. The game is as follows: 我们来玩一个游戏,规则如下: I pick a number from 1 to n. Y ...