1.链接地址:

http://poj.org/problem?id=1631

http://bailian.openjudge.cn/practice/1631

2.题目:

Bridging signals
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 9882   Accepted: 5409

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

Source

3.思路:

4.代码:

 #include "stdio.h"
//#include "stdlib.h"
#define NUM 40002
int dp[NUM];
int c[NUM];
int a[NUM];
int bsearch(int c[],int n,int a)
{
int l = ,r = n;
int m;
while(l<=r)
{
m=(l+r)/;
if(a>c[m] && a<=c[m+]) return m+;
else if(a<c[m]) r=m-;
else l=m+;
}
}
int LIS(int a[],int n)
{
int i,j,size=;
dp[]=;c[]=a[];
for(i=;i<=n;i++)
{
if(a[i] <= c[]) j=;
else if(a[i] > c[size]) j=++size;
else j= bsearch(c,size,a[i]);
c[j]=a[i];dp[j];
}
return size;
}
int main()
{
int n,p;
int i,j;
int ans;
scanf("%d",&n);
for(i=;i<n;i++)
{
scanf("%d",&p);
for(j=;j<=p;j++) scanf("%d",&a[j]);
int ans = LIS(a,p);
printf("%d\n",ans);
}
//system("pause");
return ;
}

OpenJudge/Poj 1631 Bridging signals的更多相关文章

  1. POJ 1631 Bridging signals

    Bridging signals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9441   Accepted: 5166 ...

  2. poj 1631 Bridging signals (二分||DP||最长递增子序列)

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

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

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

  4. POJ 1631 Bridging signals(LIS 二分法 高速方法)

    Language: Default Bridging signals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 1076 ...

  5. POJ 1631 Bridging signals & 2533 Longest Ordered Subsequence

    两个都是最长上升子序列,所以就放一起了 1631 因为长度为40000,所以要用O(nlogn)的算法,其实就是另用一个数组c来存储当前最长子序列每一位的最小值,然后二分查找当前值在其中的位置:如果当 ...

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

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

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

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

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

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

  9. POJ 1631 Bridging signals(LIS的等价表述)

    把左边固定,看右边,要求线不相交,编号满足单调性,其实是LIS的等价表述. (如果编号是乱的也可以把它有序化就像Uva 10635 Prince and Princess那样 O(nlogn) #in ...

随机推荐

  1. [转]强大的vim配置文件,让编程更随意

    转自:http://www.cnblogs.com/ma6174/archive/2011/12/10/2283393.html 花了很长时间整理的,感觉用起来很方便,共享一下. 我的vim配置主要有 ...

  2. NSDictionary或NSArray与JSON字符串相互转换

    在iOS 5 中,苹果引入了一个解析JSON串的NSJSONSerialization类.通过该类,我们可以完成JSON数据与NSDictionary和NSArray之间的转化. 以前,我记得我用的是 ...

  3. 浅谈js单例模式

    单例模式就是在系统中保存一个实例,就是一个全局变量,在团队开发中,为了实现一些相似的功能,比如不同页面之间的表单验证,可能需求是不一样的,但是呢命名可能一样,这时就会产生冲突,这时候单例模式就能很好的 ...

  4. Ⅵ.spring的点点滴滴--自定义类型转换器

    承接上文 自定义类型转换器 .net篇(环境为vs2012+Spring.Core.dll v1.31) public class CustomeConverter : TypeConverter{ ...

  5. java实现文件复制功能

    原理:把原文件读入到输入流里,然后利用输出流写入到新的文件. 代码如下: /** * 复制文件 * @param fromFile * @param toFile * <br/> * 20 ...

  6. POJ 3621Sightseeing Cows

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9851   Accepted: 3375 Description Farme ...

  7. Oracle数据库编程:PL/SQL编程基础

    2.PL/SQL编程基础: PL/SQL块:        declare        定义部分        begin        执行部分        exception        异 ...

  8. python中的对象拷贝

    python中.进行函数參数传递或者返回值时,假设是一般的变量,会拷贝传递.假设是列表或字典则是引用传递.那python怎样对列表和字典进行拷贝传递呢:标准库的copy模块提供了两个方法:copy和d ...

  9. 选择排序、插入排序、冒泡排序python实现

    选择排序的时间复杂度为O(n^2),是不稳定的排序 冒泡排序的时间复杂度最好情况下为O(n),最坏情况下为O(n^2),平均情况下为O(n^2),是稳定的排序 插入排序的时间复杂度最好情况下为O(n) ...

  10. Flash中的文本应用

    1.分离文本 (1)为什么要分离文本? 由于某些操作不能直接作用于文本对象,比如为文本填充渐变色,以及调整文本的外形. 上述操作仅仅作用于图像对象,所以须要将文本打散,使其具有和图形相似的属性. 注意 ...