(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 最长公共子序列 题意 给你两个字符串,求出这两个字符串的最长公共子序列,这里的子序列不一定是连续的,只要满足前后关系就可以. 解题思路 这个当然 ...
随机推荐
- X265编码效率仍然低
本次测试软件环境:Intel Celeron双核 2.60 Ghz CPU; 4GB 内存:安装 Ubuntu 13.04 hzsx@hzsx-server:~$ lsb_release -a No ...
- SQL SERVER 导入EXCEL的存储过程
1.先在查询分析器里执行 exec sp_configure "show advanced options",1 reconfigure exec sp_configure &qu ...
- Xcode5 上使用Base SDK iOS6程序和iOS6模拟器
Xcode 5默认自带SDK 7.0,升级Xcode 5后,Xcode.5就没了,这样我想编译SDK 6.x的程序就难办了(除非同时安装Xcode 4.x和Xcode 5.x两个版本Xcode).其中 ...
- canvas createRadialGradient 用法
径向渐变,就是环形的渐变了,由圆心(或者是较小的同心圆)开始向外扩散渐变的效果,听着有些抽象,往下看图一下子就明白了.线性渐变指定了起点和终点,径向渐变则指定了开始的结束园的圆心和半径.这里使用cre ...
- SSM框架整合基本操作
1.首先导入各种需要的配置包,在这里个人的习惯就是先导入mybatis相关包,然后通过编程软件集成一个spring3.0或者spring3.1进来并选择里面相应的包,这样就不需要我们自己去导入相应的s ...
- KVC 和KVO浅谈
一.KVC:Key-Value -Coding :直译为:键-值-代码:即:对键值进行改变的代码方法 该方法是OC(Object-C)为我们提供的一个不通过初始化方法而直接改变对象实例变量值的一种 ...
- Fastjson反序列化泛型类型时候的一个问题
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.u ...
- Sublime 格式化代码 快捷键以及插件使用
来自Vic___:http://blog.csdn.net/vic___ 其实在sublime中已经自建了格式化按钮: Edit -> Line -> Reindent 只是sub ...
- Android开发书籍推荐
当你看到这些文字时,那么恭喜你,你可能选择了一个无限可能的方向. Android,Google出品,信誉保证,你值得深入研究. 学习一样新事物或许有多种方式,报培训班,看视频,向高手请教等等,但一本好 ...
- webstrom热键[持续更新]
1.Ctrl+ Shift + A -- 为了加快寻找菜单命令或工具栏操作,你并不需要看菜单.只有按Ctrl+ Shift + A(说明|查找操作主菜单上),并开始输入动作的名称. . 2.Ctr ...