(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 最长公共子序列 题意 给你两个字符串,求出这两个字符串的最长公共子序列,这里的子序列不一定是连续的,只要满足前后关系就可以. 解题思路 这个当然 ...
随机推荐
- Cocos2d-x MultipleTouch & CCControllButton's confusion
在cocos2dx的程序设计中有时候会遇到需要多点触摸的功能,下面先介绍一下在cocos2dx中多点触摸的一般规则,然后介绍我遇到的一个有关多点触摸的情景的解决方案. (一)使用多点触摸规则: 关于多 ...
- 最新版postgresql+pgboucer安装
安装postgresql: wget https://pgbouncer.github.io/downloads/files/1.7.2/pgbouncer-1.7.2.tar.gz wget htt ...
- 调用webservice,解析返回数据为xml格式的字符串,进行数据绑定
DataSet ds = new DataSet(); byte[] byteArray = System.Text.Encoding.Unicode.GetBytes("<?xml ...
- Sublime Text 3103 Crack 破解 注册码
随机复制下面的几四个注册码 粘贴到sublime text 3(Build 3103)注册框 就可以了! ----------------------------------------------- ...
- SVN高速新手教程
因为做Zip和Rar解析的时候,找到了mucommander工具,可将其jar包导入项目里执行发现报:类型转换错误,org.apache.commons.logging.impl.Log4JLogge ...
- SilkTest天龙八部系列3-动态父窗口
SilkTest中用parent语句来声明某个window的父窗口,这会帮助silktest在识别该对象时检查其是否是由该父窗口打开,如果parent语句申明的父窗口并不存在,那么该对象无法被正确识别 ...
- 简洁 Abstract Factory模式(3.1)
镇楼 在某些书中使用了二维图说明抽象工厂模式.非常好,可是yqj2065不喜欢他们的产品族/产品等级,改成品牌/产品类型. 抽象工厂模式(abstract factory pattern)较工厂方法模 ...
- redis-BOOK
https://www.gitbook.com/book/gnuhpc/redis-all-about/details
- cocos2dx下最大纹理大小取决于平台
原文:http://www.cocos2d-x.org/wiki/Max_size_of_textures_in_cocos2d-x_depends_on_each_platform 在理论上,coc ...
- iOS开发经验总结(上)
在iOS开发中经常需要使用的或不常用的知识点的总结,几年的收藏和积累(踩过的坑). 一. iPhone Size 手机型号 屏幕尺寸 iPhone 4 4s 320 * 480 iPhone 5 5s ...