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. 第二次作业第2题_JH

    2.每人自己建立一个HelloWorld项目,练习使用git的add/commit/push/pull/fetch/clone等基本命令.比较项目的新旧版本的差别. (1)创建一个HelloWorld ...

  2. sysctl

    /proc/sys目录下存放着大多数内核参数,并且可以在系统运行时进行更改,不过重新启动机器就会失效./etc/sysctl.conf是一个允许改变正在运行中的Linux系统的接口,它包含一些TCP/ ...

  3. mapping 详解5(dynamic mapping)

    概述 在使用 ES 的时,我们不需要事先定义好映射设置就可以直接向索引中导入文档.ES 可以自动实现每个字段的类型检测,并进行 mapping 设置,这个过程就叫动态映射(dynamic mappin ...

  4. java编程常用技术

    一:将String字符串放在最前面 防止发生NullPointerException异常,我们通常把String字符串放在equals方法的左边来比较,这样可以有效的避免 空指针异常的发生. 第一种情 ...

  5. Matlab中tic和toc用法

    简单地说,tic和toc是用来记录matlab命令执行的时间 tic用来保存当前时间,而后使用toc来记录程序完成时间. 两者往往结合使用,用法如下: tic operations toc 显示时间单 ...

  6. 百度地图SDK下载以及创建应用(申请Key)和本地导入Demo

    一.百度地图SDK下载 http://lbsyun.baidu.com/sdk/download?selected=location 选择全部,然后分别下载开发包.示例代码.类参考. 二.创建应用(申 ...

  7. JAVA问问

    一.java中的类和方法 java是面向对象的 类就可以看做一个对象 属性是这个对象拥有什么 方法是这个对象可以做什么 Eg: 类:Person 属性:eyes mouth 方法:eat 解释: Pe ...

  8. 冒泡排序小实例 php

    源代码如下,仅用于参考: <?php$a = array(10,2,36,14,10,25,23,85,99,45); for($j=0;$j<9;$j++){ for($i=0;$i&l ...

  9. getOutputStream() has already been called for this response异常的原因和解决方法

    今天在调试一个小web项目时,验证码不显示了,而且后台报错 getOutputStream() has already been called for this response 经过查找得知: 在t ...

  10. 使用EF访问数据库,出现“System.Data.Entity.Internal.AppConfig”的类型初始值设定项引发异常。

    今天在使用的EF时候,发生了"System.Data.Entity.Internal.AppConfig"的类型初始值设定项引发异常.这样的一个错误 查了原因,原来是appconf ...