题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=1950

Bridging signals

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3711    Accepted Submission(s): 2337

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 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.

 
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
1
0
2
3
4
5
6
7
8
9
1
0
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
 分析:
LIS问题,采用n*logn的算法优化一下
#include<bits/stdc++.h>
#define max_v 100005
using namespace std;
int a[max_v],dp[max_v],len;
int select(int x)
{
int l,r,m;
l=;
r=len;
while(l<r)
{
m=l+(r-l)/;
if(dp[m]>=x)
{
r=m;
}else
{
l=m+;
}
}
return l;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
}
//dp[k]代表长度为k的LIS序列的最末元素,若有多个长度为k的上升子序列,则记录最小的那个最末元素
//dp[]中的元素是单调递增的,二分优化的时候利用这个性质 dp[]=a[];
len=;
for(int i=; i<=n; i++)
{
if(a[i]>dp[len])
{
dp[++len]=a[i];
}
else
{
int j=select(a[i]);
dp[j]=a[i];
}
}
printf("%d\n",len);
}
return ;
}

HDU 1950(LIS)的更多相关文章

  1. HDU 1950 LIS(nlogn)

    Bridging signals Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. hdu 1950 最长上升子序列(lis) nlogn算法【dp】

    这个博客说的已经很好了.http://blog.csdn.net/shuangde800/article/details/7474903 简单记录一下自己学的: 问题就是求一个数列最长上升子序列的长度 ...

  3. hdu 1025 lis 注意细节!!!【dp】

    感觉这道题浪费了我半个小时的生命......哇靠!原来输出里面当len=1时是road否则是roads!!! 其实做过hdu 1950就会发现这俩其实一样,就是求最长上升子序列.我用结构体记录要连线的 ...

  4. HDU 1950 Bridging signals (DP)

    职务地址:HDU 1950 这题是求最长上升序列,可是普通的最长上升序列求法时间复杂度是O(n*n).显然会超时.于是便学了一种O(n*logn)的方法.也非常好理解. 感觉还用到了一点贪心的思想. ...

  5. HDU 1950 Bridging signals(LIS)

    最长上升子序列(LIS)的典型变形,O(n^2)的动归会超时.LIS问题可以优化为nlogn的算法. 定义d[k]:长度为k的上升子序列的最末元素,若有多个长度为k的上升子序列,则记录最小的那个最末元 ...

  6. HDU 1950 Bridging signals (LIS,O(nlogn))

    题意: 给一个数字序列,要求找到LIS,输出其长度. 思路: 扫一遍+二分,复杂度O(nlogn),空间复杂度O(n). 具体方法:增加一个数组,用d[i]表示长度为 i 的递增子序列的最后一个元素, ...

  7. Bridging signals hdu 1950 (最长上升子序列)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=1950 题意:求最长上升(不连续or连续)子序列 推荐博客链接: http://blog.csdn.n ...

  8. Super Jumping! Jumping! Jumping!(hdu 1087 LIS变形)

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  9. HDU 1025 LIS二分优化

    题目链接: acm.hdu.edu.cn/showproblem.php?pid=1025 Constructing Roads In JGShining's Kingdom Time Limit: ...

随机推荐

  1. Django基础五之django模型层(二)多表操作

    一 创建模型 表和表之间的关系 一对一.多对一.多对多 ,用book表和publish表自己来想想关系,想想里面的操作,加外键约束和不加外键约束的区别,一对一的外键约束是在一对多的约束上加上唯一约束. ...

  2. ArcGIS for JavaScript 关于路径开发的一些记录(二)

    又是高度集中开发路径模块的一天.真希望自己以后都可以如此的专注和高效(虽然知道很难一直都保持这样的状态,我会坚持的~哈哈哈) 言归正传,今天开发了途径点的功能和改进了些相关起点.终点的代码.先说一下我 ...

  3. syscall to rop

    前言 hitcon 2017 的 start 题,比较简单,练练手. 题目链接: https://gitee.com/hac425/blog_data/tree/master/hitcon2017 正 ...

  4. 配置hive使用mysql存储metadata metadatastore

        hive默认使用derby数据库保存元数据,derby数据库比较小众,并且一次只能打开一个会话,一般修改为mysql数据库. 1.修改conf/hive-site.xml配置项: <pr ...

  5. 带你从零学ReactNative开发跨平台App开发[expo 打包发布](八)

    ReactNative跨平台开发系列教程: 带你从零学ReactNative开发跨平台App开发(一) 带你从零学ReactNative开发跨平台App开发(二) 带你从零学ReactNative开发 ...

  6. JQuery this和$(this)的区别

    this其实是一个Html 元素. $this 只是个变量名,加$是为说明其是个jquery对象. 而$(this)是个转换,将this表示的dom对象转为jquery对象,这样就可以使用jquery ...

  7. leetCode题解之寻找string中最后一个word的长度

    1.题目描述 返回一个 string中最后一个单词的长度.单词定义为没有空格的连续的字符,比如 ‘a’,'akkk'. 2.问题分析 从后向前扫描,如果string是以空格‘  ’结尾的,就不用计数, ...

  8. SQLServer Temp tables 数据疑问

    1. 现象 使用Cacti监控,有关于临时表的一个图形 可以看到正在使用的临时表Active Temp Tables的数量非常大,并且在非工作时间,也维持在400个左右.感觉非常奇怪,所以追查下! 2 ...

  9. 机器学习中正则惩罚项L0/L1/L2范数详解

    https://blog.csdn.net/zouxy09/article/details/24971995 原文转自csdn博客,写的非常好. L0: 非零的个数 L1: 参数绝对值的和 L2:参数 ...

  10. JWT能够干什么,不应该干什么?

    http://cryto.net/~joepie91/blog/2016/06/13/stop-using-jwt-for-sessions/ At the start of this article ...