hdu----(1950)Bridging signals(最长递增子序列 (LIS) )
Bridging signals
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 667 Accepted Submission(s): 443
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.
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.
each test scenario, output one line containing the maximum number of
signals which may be routed on the silicon surface without crossing each
other.
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
//#define LOCAL
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=; int str[maxn],ans[maxn],dp[maxn];
int n,dd; int LIS(int a[], int n)
{
int i, j,res=;
for(i=;i<=n;i++)
ans[i]=inf;
memset(dp,,sizeof(int)*(n+));
for(i=;i<=n;++i)
{ dp[i]=lower_bound(ans+,ans+n+,a[i])-ans;
// j=bsearch(c, size, a[i]); //在已有的序列中进行替换
if(res<dp[i])res=dp[i];
j=i;
if(j>&&ans[dp[j]]>a[j])
ans[dp[j]]=a[j];
}
return res;
} int main()
{
#ifdef LOCAL
freopen("test.in","r",stdin);
#endif
int cas;
scanf("%d",&cas);
while(cas--){ scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",str+i);
}
printf("%d\n",LIS(str,n));
}
return ;
}
hdu----(1950)Bridging signals(最长递增子序列 (LIS) )的更多相关文章
- hdu1950 Bridging signals 最长递增子序列
用一个数组记下递增子序列长度为i时最小的len[i],不断更新len数组,最大的i即为最长递增子序列的长度 #include<cstdio> #include<algorithm&g ...
- 2.16 最长递增子序列 LIS
[本文链接] http://www.cnblogs.com/hellogiser/p/dp-of-LIS.html [分析] 思路一:设序列为A,对序列进行排序后得到B,那么A的最长递增子序列LIS就 ...
- 动态规划(DP),最长递增子序列(LIS)
题目链接:http://poj.org/problem?id=2533 解题报告: 状态转移方程: dp[i]表示以a[i]为结尾的LIS长度 状态转移方程: dp[0]=1; dp[i]=max(d ...
- 最长回文子序列LCS,最长递增子序列LIS及相互联系
最长公共子序列LCS Lintcode 77. 最长公共子序列 LCS问题是求两个字符串的最长公共子序列 \[ dp[i][j] = \left\{\begin{matrix} & max(d ...
- 一个数组求其最长递增子序列(LIS)
一个数组求其最长递增子序列(LIS) 例如数组{3, 1, 4, 2, 3, 9, 4, 6}的LIS是{1, 2, 3, 4, 6},长度为5,假设数组长度为N,求数组的LIS的长度, 需要一个额外 ...
- HDU 1950 Bridging signals(LIS)
最长上升子序列(LIS)的典型变形,O(n^2)的动归会超时.LIS问题可以优化为nlogn的算法. 定义d[k]:长度为k的上升子序列的最末元素,若有多个长度为k的上升子序列,则记录最小的那个最末元 ...
- 动态规划 - 最长递增子序列(LIS)
最长递增子序列是动态规划中经典的问题,详细如下: 在一个已知的序列{a1,a2,...,an}中,取出若干数组组成新的序列{ai1,ai2,...,aim},其中下标i1,i2,...,im保持递增, ...
- 最长递增子序列LIS再谈
DP模型: d(i) 以第 i 个元素结尾的最长递增子序列的长度. 那么就有 d(i) = max(d(j)) + 1;(j<i&&a[j]<a[i]),答案 max(d( ...
- 算法面试题 之 最长递增子序列 LIS
找出最长递增序列 O(NlogN)(不一定连续!) 参考 http://www.felix021.com/blog/read.php?1587%E5%8F%AF%E6%98%AF%E8%BF%9E%E ...
随机推荐
- 【转】Ajax中send方法参数的使用(get/post)
Ajax中send方法参数的使用 一般情况下,使用Ajax提交的参数多是些简单的字符串,可以直接使用GET方法将要提交的参数写到open方法的url参数中,此时send方法的参数为null. 例如 : ...
- SDP学习笔记
一.SDP规范了回话描述的格式,一般结合会话协议共同工作. 常见的会话传送协议包括:SAP(Session Announcement Protocol 会话公告协议),SIP,RTSP,HTTP,和使 ...
- [转自老马的文章]用MODI OCR 21种语言
作者:马健邮箱:stronghorse_mj@hotmail.com发布:2007.12.08更新:2012.07.09按照<MODI中的OCR模块>一文相关内容进行修订2012.07.0 ...
- python tools: iPython Notebook
Introducing IPython Notebook IPython isn't a different programming language, it's just a set of comp ...
- maven的聚合与继承5
一.聚合 如果我们想一次构建多个项目模块,那我们就需要对多个项目模块进行聚合 1.1.聚合配置代码 1 <modules> 2 <module>模块一</module&g ...
- ssh免密码登陆及其原理
ssh 无密码登录要使用公钥与私钥.linux下可以用用ssh-keygen生成公钥/私钥对,下面我以CentOS为例. 有机器A(192.168.1.155),B(192.168.1.181).现想 ...
- boost线程的问题:
可以看看这里:http://blog.csdn.net/misskissc/article/details/9859753 我的总结: 1,用thread类来创建一个线程,它的构结函数 : (1)th ...
- Ruby方法
Ruby 方法 Ruby 方法与其他编程语言中的函数类似.Ruby 方法用于捆绑一个或多个重复的语句到一个单元中. 方法名应以小写字母开头.如果您以大写字母作为方法名的开头,Ruby 可能会把它当作常 ...
- 浅谈 MVP in Android
一.概述 对于MVP(Model View Presenter),大多数人都能说出一二:“MVC的演化版本”,“让Model和View完全解耦”等等.本篇博文仅是为了做下记录,提出一些自己的看法,和帮 ...
- golang时间
//获取本地location toBeCharge := "2015-01-01 00:00:00" //待转化为时间戳的字符串 注意 这里的小时和分钟还要秒必须写 因为是跟着模板 ...