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 ...
随机推荐
- GBrowse配置相关资料
GBrowse配置相关资料(形状.颜色.配置.gff3) http://gmod.org/wiki/Glyphs_and_Glyph_Optionshttp://gmod.org/wiki/GBrow ...
- linux sudo apt-get用法详解
APT的使用(Ubuntu Linux软件包管理工具一)apt-cache search # ------(package 搜索包)apt-cache show #------(package 获取包 ...
- python 内建函数功能函数 abs() coerce() divmod() round() pow()
>>> abs(-1)1>>> abs(10.) 10.0>>> abs(1.2-2.1j)2.4186773244895647>> ...
- 06_在web项目中集成Spring
在web项目中集成Spring 一.使用Servlet进行集成测试 1.直接在Servlet 加载Spring 配置文件 ApplicationContext applicationContext = ...
- ubuntu1604安装体验
昨天安装了ubuntu 16 安装成了双系统,这样的速度才能接受. 各种软件支持的都还算不错.除了启动时候原始的气息,启动之后挺稳定的. 最让人开心的是新的unity的设置更加丰富了,可以自动隐藏,更 ...
- sqlserver前面加N解释
From : http://lzde360.blog.163.com/blog/static/6780720820111026112033917/ 加上 N 代表存入数据库时以 Unicode 格式存 ...
- git学习笔记08-分支管理策略-实际上我们应该怎么应用分支
Git用Fast forward模式(快进模式),但这种模式下,删除分支后,会丢掉分支信息. 如果要强制禁用Fast forward模式,Git就会在merge时生成一个新的commit,这样,从分支 ...
- DOM 操作XML(CRUD)
<?xml version="1.0" encoding="UTF-8" standalone="no"?><书架> ...
- Data Science 和 Finance 两个领域的融合是什么样子的?
Data Science 和 Finance 两个领域的融合是什么样子的? 2015-05-24 董可人 现在大部分人所说的Quant一般是指各大投行里做衍生品定价,信用评估,风险控制之类工作的人,这 ...
- servlet文件上传
1.获取文件上传路径 String path=request.getServletContext.getRePath("/WEB-INF/resources"); 2.获得工厂 3 ...