Bridging signals(NlogN最长上升子序列)
Bridging signals
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2354 Accepted Submission(s): 1536
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.
6
4
2
6
3
1
5
10
2
3
4
5
6
7
8
9
10
1
8
8
7
6
5
4
3
2
1
9
5
8
9
2
3
1
7
4
6
9
1
4
/*----------------------------------------------
File: F:\ACM源代码\动态规划\最长上升子序列\HDU1950.cpp
Date: 2017/5/30 10:24:29
Author: LyuCheng
----------------------------------------------*/
#include <bits/stdc++.h>
#define MAXN 40005 using namespace std; int n,t,len;
int b[MAXN],d[MAXN];
int binary_seacher(int i){
int left,right,mid;
left=,right=len;
while(left<right){
mid=left+(right-left)/;
if(b[mid]>=d[i]) right=mid;
else left=mid+;
}
return left;
}
int main(int argc, char *argv[])
{
// freopen("in.txt","r",stdin);
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&d[i]);
}
b[]=d[];
len=;
for(int i=;i<=n;i++){
if(b[len]<d[i]){
b[++len]=d[i];
}else{
int pos=binary_seacher(i);
b[pos]=d[i];
}
}
printf("%d\n",len);
}
return ;
}
Bridging signals(NlogN最长上升子序列)的更多相关文章
- (hdu)1950 Bridging signals(最长上升子序列)
Problem Description 'Oh no, they've done it again', cries the chief designer at the Waferland chip f ...
- POJ 1631 Bridging signals DP(最长上升子序列)
最近一直在做<挑战程序设计竞赛>的练习题,感觉好多经典的题,都值得记录. 题意:给你t组数据,每组数组有n个数字,求每组的最长上升子序列的长度. 思路:由于n最大为40000,所以n*n的 ...
- POJ 1631 Bridging signals (LIS:最长上升子序列)
题意:给你一个长为n(n<=40000)的整数序列, 要你求出该序列的最长上升子序列LIS. 思路:要求(nlogn)解法 令g[i]==x表示当前遍历到的长度为i的所有最长上升子序列中的最小序 ...
- POJ - 1631 Bridging signals(最长上升子序列---LIS)
题意:左右各n个端口,已知n组线路,要求切除最少的线路,使剩下的线路各不相交,按照左端口递增的顺序输入. 分析: 1.设左端口为l,右端口为r,因为左端口递增输入,l[i] < l[j](i & ...
- HDU 1950 Bridging signals【最长上升序列】
解题思路:题目给出的描述就是一种求最长上升子序列的方法 将该列数an与其按升序排好序后的an'求出最长公共子序列就是最长上升子序列 但是这道题用这种方法是会超时的,用滚动数组优化也超时, 下面是网上找 ...
- Bridging signals---hdu1950(最长上升子序列复杂度n*log(n) )
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1950 一直只知道有除n*n的算法之外的求LIS,但是没学过,也没见过,今天终于学了一下,dp[i]表 ...
- {POJ}{3903}{Stock Exchange}{nlogn 最长上升子序列}
题意:求最长上升子序列,n=100000 思路:O(N^2)铁定超时啊....利用贪心的思想去找答案.利用栈,每次输入数据检查栈,二分查找替换掉最小比他大的数据,这样得到的栈就是更优的.这个题目确实不 ...
- 最长上升子序列算法(n^2 及 nlogn) (LIS) POJ2533Longest Ordered Subsequence
问题描述: 一个数的序列bi,当b1 < b2 < ... < bS的时候,我们称这个序列是上升的.对于给定的一个序列(a1, a2, ..., aN),我们可以得到一些上升的子序列 ...
- poj 1631 Bridging signals (二分||DP||最长递增子序列)
Bridging signals Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9234 Accepted: 5037 ...
随机推荐
- asp.net mvc项目实记-开启伪静态-Bundle压缩css,js
百度这些东西,还是会浪费了一些不必要的时间,记录记录以备后续 一.开启伪静态 如果不在web.config中配置管道开关则伪静态无效 首先在RouteConfig.cs中中注册路由 routes.Ma ...
- socket端口外网无法连接解决方法
用socket做了个程序,本地测试没有问题,发布到服务器上时连接不上,用telnet测试连接失败 服务器上netstat -a 查看端口情况,127.0.0.1绑定端口9300处于监听状态,如下图: ...
- bzoj3209 花神的数论题 (二进制数位dp)
二进制数位dp,就是把原本的数字转化成二进制而以,原来是10进制,现在是二进制来做,没有想像的那么难 不知到自己怎么相出来的...感觉,如果没有一个明确的思路,就算做出来了,也并不能锻炼自己的能力,因 ...
- 用MXNet实现mnist的生成对抗网络(GAN)
用MXNet实现mnist的生成对抗网络(GAN) 生成式对抗网络(Generative Adversarial Network,简称GAN)由一个生成网络与一个判别网络组成.生成网络从潜在空间(la ...
- IDL 指针
IDL指针与C.C++和FORTRAN等其他程序语言的指针不同,它所处的多变量是可以动态分配内存的全局变量,不只想真正的内存地址 1.创建和访问指针 指针用指针函数Ptr_New()来创建,通过“*” ...
- SVN版本控制图标经常延时显示或未显示问题解决方法
项目中,使用svn经常遇到,文件或文件夹图标延时显示或未显示的问题,终于找到办法解决 客户端:TortoiseSVN
- Jquery实现弹出选择框选择后返回,支持多级分类
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- 在C#中实现串口通信的方法
通常,在C#中实现串口通信,我们有四种方法: 第一:通过MSCOMM控件这是最简单的,最方便的方法.可功能上很难做到控制自如,同时这个控件并不是系统本身所带,所以还得注册,不在本文讨论范围.可以访问h ...
- 不错的JQuery屏幕居中提示信息封装,使用方便,可集成到项目
function showLoad(tipInfo, type, autohide) { var pic = ""; switch (type) { case 0: // load ...
- 云计算---openstack各服务端口使用情况
端口占用情况 端口情况可以使用ss -tanp命令进行查看 监听的所有端口ss -tanp | grep LISTEN 基础服务 22 --SSH 3306 --MariaDB(MySQL) 2701 ...