(hdu)1950 Bridging signals(最长上升子序列)
Problem 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 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 . 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 . The ports of the two functional blocks are numbered from to p, from top to bottom. The signal mapping is described by a permutation of the numbers to p in the form of a list of p unique numbers in the range 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. 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<, 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 Sample Output
题意:T组例子 N个点 i与a[i]相连 在不交叉的情况下,相连最对的点
方法 求最长上升子序列 运用函数 upper_bound(a,a+k,num)-a;二分查找
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include <math.h>
#include<queue>
#define ll long long
#define INF 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof(a));
#define N 51100
using namespace std;
int a[N];
int main()
{
int t,num,n,m;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
a[]=;int k=;
for(int i=;i<n;i++)
{
scanf("%d",&num);
if(num>a[k-])
{
a[k++]=num;
}
else
{
m=upper_bound(a,a+k,num)-a;///从数组a中查找第一个比num大的树,返回下标
a[m]=num;
}
}
printf("%d\n",k-);
}
return ;
}
(hdu)1950 Bridging signals(最长上升子序列)的更多相关文章
- HDU 1950 Bridging signals【最长上升序列】
		
解题思路:题目给出的描述就是一种求最长上升子序列的方法 将该列数an与其按升序排好序后的an'求出最长公共子序列就是最长上升子序列 但是这道题用这种方法是会超时的,用滚动数组优化也超时, 下面是网上找 ...
 - HDU 1950 Bridging signals (DP)
		
职务地址:HDU 1950 这题是求最长上升序列,可是普通的最长上升序列求法时间复杂度是O(n*n).显然会超时.于是便学了一种O(n*logn)的方法.也非常好理解. 感觉还用到了一点贪心的思想. ...
 - hdu----(1950)Bridging signals(最长递增子序列 (LIS) )
		
Bridging signals Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
 - hdu1950 Bridging signals 最长递增子序列
		
用一个数组记下递增子序列长度为i时最小的len[i],不断更新len数组,最大的i即为最长递增子序列的长度 #include<cstdio> #include<algorithm&g ...
 - HDU 1950 Bridging signals(LIS)
		
最长上升子序列(LIS)的典型变形,O(n^2)的动归会超时.LIS问题可以优化为nlogn的算法. 定义d[k]:长度为k的上升子序列的最末元素,若有多个长度为k的上升子序列,则记录最小的那个最末元 ...
 - hdu 1950  Bridging signals 求最长子序列 ( 二分模板  )
		
Bridging signals Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
 - HDU 1950 Bridging signals (LIS,O(nlogn))
		
题意: 给一个数字序列,要求找到LIS,输出其长度. 思路: 扫一遍+二分,复杂度O(nlogn),空间复杂度O(n). 具体方法:增加一个数组,用d[i]表示长度为 i 的递增子序列的最后一个元素, ...
 - HDU 1950 Bridging signals
		
那么一大篇的题目描述还真是吓人. 仔细一读其实就是一个LIS,还无任何变形. 刚刚学会了个二分优化的DP,1A无压力. //#define LOCAL #include <iostream> ...
 - HDU 1159 Common Subsequence 最长公共子序列
		
HDU 1159 Common Subsequence 最长公共子序列 题意 给你两个字符串,求出这两个字符串的最长公共子序列,这里的子序列不一定是连续的,只要满足前后关系就可以. 解题思路 这个当然 ...
 
随机推荐
- DevExpress控件XtraGrid的Master-Detail中DetailViewCaption显示问题
			
今天遇到XtraGrid身档抬头显示不对问题,查找了很多资料后未找到解决办法,后浏览至此文作者发现解决问题的方法就是:DataSet中的RelactionName跟DetailGridview的Lea ...
 - hadoop-2.6.0.tar.gz + spark-1.5.2-bin-hadoop2.6.tgz  的集群搭建(3节点和5节点皆适用)
			
本人呕心沥血所写,经过好一段时间反复锤炼和整理修改.感谢所参考的博友们!同时,欢迎前来查阅赏脸的博友们收藏和转载,附上本人的链接.http://www.cnblogs.com/zlslch/p/584 ...
 - psd via fft and pwelch
			
%fft and pwelch方法求取功率谱load x.mat Fs = 1; t = (0:1/Fs:1-1/Fs).'; Nx = length(x); % Window data w = ha ...
 - editplus如何设置不自动备份
			
依次选择:工具,参数设置,文件(默认展开的,要缩回),然后看右边“保存文件时创建备份”,前面的框不要打勾,应用,确定
 - Lucene教程具体解释
			
(建立索引)] )中生成的索引文件的存放地址.详细步骤简单介绍例如以下: 1.创建Directory对象,索引目录 2.创建IndexSearch对象,建立查询(參数是Directory对象) 3.创 ...
 - LINUX 系统备份
			
系统备份是系统管理工作中十分重要的一个环切,本文详细介绍了各种Linux系统的备份方法,相信对大家的日常管理工作有所帮助. 备份是一项重要的工作,但是很多人没有去做.一旦由于使用不当造成数据丢失,备份 ...
 - MySQL 数据库常用命令 超级实用版分享
			
1.MySQL常用命令 create database name; 创建数据库 use databasename; 选择数据库 drop database name 直接删除数据库,不提醒 show ...
 - [转] Android进阶——安卓接入微信,获取OpenID
			
PS: sendAuthRequest拿到code,通过code拿到access_token和openId,access_token可以拿到用户的信息 http://blog.csdn.net/hao ...
 - 使用OKHttp模拟登陆知乎,兼谈OKHttp中Cookie的使用!
			
本文主要是想和大家探讨技术,让大家学会Cookie的使用,切勿做违法之事! 很多Android初学者在刚开始学习的时候,或多或少都想自己搞个应用出来,把自己学的十八般武艺全都用在这个APP上,其实这个 ...
 - oracle修改字段类型
			
有一个表名为tb,字段段名为name,数据类型nchar(20). 1.假设字段数据为空,则不管改为什么字段类型,可以直接执行:alter table tb modify (name nvarchar ...