hdoj 1950 Bridging signals【二分求最大上升子序列长度】【LIS】
Bridging signals
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 961 Accepted Submission(s):
627
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 rossing each other, is imminent. Bearing in mind that there may be
housands 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?

Figure 1. To the left: The two blocks' ports
and their signal mapping (4,2,6,3,1,5). To the right: At most three signals may
be routed on the silicon surface without crossing each other. The dashed signals
must be bridged.
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 pecifies 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.
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.
maximum number of signals which may be routed on the silicon surface without
crossing each other.
#include<stdio.h>
#include<string.h>
int main()
{
int t;
int p,top,l,r,mid,i,m;
int a[44000];
scanf("%d",&t);
while(t--)
{
scanf("%d",&p);
scanf("%d",&a[0]);
int top=0;
for(i=1;i<p;i++)
{
scanf("%d",&m);
if(a[top]<m)
a[++top]=m;
else
{
l=0;r=top;mid=0;
while(r>=l)
{
mid=(r+l)/2;
if(a[mid] < m)
l=mid+1;
else
r=mid-1;
}
a[r+1]=m;
}
}
printf("%d\n",top+1);
}
return 0;
}
hdoj 1950 Bridging signals【二分求最大上升子序列长度】【LIS】的更多相关文章
- (hdu)1950 Bridging signals(最长上升子序列)
Problem Description 'Oh no, they've done it again', cries the chief designer at the Waferland chip f ...
- hdu 1950 Bridging signals 求最长子序列 ( 二分模板 )
Bridging signals Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- poj 1631 Bridging signals (二分||DP||最长递增子序列)
Bridging signals Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9234 Accepted: 5037 ...
- HDU 1950 Bridging signals【最长上升序列】
解题思路:题目给出的描述就是一种求最长上升子序列的方法 将该列数an与其按升序排好序后的an'求出最长公共子序列就是最长上升子序列 但是这道题用这种方法是会超时的,用滚动数组优化也超时, 下面是网上找 ...
- HDU 1950 Bridging signals (DP)
职务地址:HDU 1950 这题是求最长上升序列,可是普通的最长上升序列求法时间复杂度是O(n*n).显然会超时.于是便学了一种O(n*logn)的方法.也非常好理解. 感觉还用到了一点贪心的思想. ...
- HDU 1950 Bridging signals(LIS)
最长上升子序列(LIS)的典型变形,O(n^2)的动归会超时.LIS问题可以优化为nlogn的算法. 定义d[k]:长度为k的上升子序列的最末元素,若有多个长度为k的上升子序列,则记录最小的那个最末元 ...
- Poj 1631 Bridging signals(二分+DP 解 LIS)
题意:题目很难懂,题意很简单,求最长递增子序列LIS. 分析:本题的最大数据40000,多个case.用基础的O(N^2)动态规划求解是超时,采用O(n*log2n)的二分查找加速的改进型DP后AC了 ...
- HDU 1950 Bridging signals
那么一大篇的题目描述还真是吓人. 仔细一读其实就是一个LIS,还无任何变形. 刚刚学会了个二分优化的DP,1A无压力. //#define LOCAL #include <iostream> ...
- HDU 1950 Bridging signals (LIS,O(nlogn))
题意: 给一个数字序列,要求找到LIS,输出其长度. 思路: 扫一遍+二分,复杂度O(nlogn),空间复杂度O(n). 具体方法:增加一个数组,用d[i]表示长度为 i 的递增子序列的最后一个元素, ...
随机推荐
- SQL的数据类型
Character 字符串: 数据类型 描述 存储 char(n) 固定长度的字符串.最多 8,000 个字符. N的范围1-8000 varchar(n) 可变长度的字符串.最多 8,000 个字符 ...
- window远程连接linux
一.字符界面连接Linux 1.直接使用window自带的telnet. 2.但现在Linux一般都不启用telnet,而是启用ssh.这样的话,window就要安装客户端来访问Linux了.这 ...
- JAVA学习-基础知识
1.Java程序都是以类的形式编写的.2.存放源代码的文件叫源文件.(电脑不能直接看懂的,需要编译一下,电脑才能懂)如何编译源文件?用javac命令输入"javac 123.Java&quo ...
- Windows7 QT5.6.0(64位)使用mysql(64位)环境搭建详解
1 说明 使用环境为:Windows7 VS2015 QT5.6.0(64位),MYSQL 5.7.13(64位). 网上各种错误.模糊.抽象的资料,配置环境花了半天,痛定思痛,总结出来,方便后来人. ...
- 获取动态SQL查询语句返回值(sp_executesql)
在写存储过程时经常会遇到需要拼接SQL语句的情况,一般情况下仅仅是为了执行拼接后的语句使用exec(@sql)即可. 而今天的一个存储过程却需要获取动态SQL的查询结果. 需求描述:在某表中根据Id值 ...
- jQuery提供的小方法
jQuery提供的小方法: 1.选择器 + 事件 + 函数 = 复杂的交互 2.循环处理与选择器匹配的各个元素:each() $("#").each(function(){ ...
- MySQL简单优化
1:对 MySQL 优化是一个综合性的技术,主要包括: a.标的设计合理(符合 3NF) b.添加适当索引(index)(普通索引.主键索引.唯一索引 unique.全文索引) ...
- Xcode6插件开发
工欲善其事必先利其器,Xcode是我们做iOS Dev必须掌握的一款开发工具. Xcode本身也是一门Cocoa程序,与其来说它是一个Cocoa程序,是不是意味着,我们可以去动态去让它做某件事,或者监 ...
- 区分html与css中的属性
CSS中id与Class的区别 1.在CSS文件里书写时,ID加前缀"#":CLASS用"." 2.id一个页面只可以使用一次:class可以多次引用. 3.I ...
- 【Java】数据库连接池技术
JDBC的问题 在程序中,我们经常要建立与数据库的连接,之后再关闭这个连接.我们知道,数据库连接对象的创建是比较消耗系统性能的,这些频繁的操作势必会消耗大量的系统资源.因此我们需要采用更高效的数据库访 ...