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 ...
随机推荐
- LuaTinker的bug和缺陷
LuaTinker的bug和缺陷 LuaTinker是一套还不错的C++代码和Lua代码的绑定库,作者是韩国人Kwon-il Lee,作者应该是参考了LuaBind后,为了简化和避免过重而实现的.其官 ...
- mysqldump使用方法(MySQL数据库的备份与恢复)
#mysqldump --help 1.mysqldump的几种常用方法: (1)导出整个数据库(包括数据库中的数据) mysqldump -u username -p dbname > dbn ...
- [HDOJ4609]3-idiots(FFT,计数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4609 题意:n个数,问取三个数可以构成三角形的组合数. FFT预处理出两个数的组合情况,然后枚举第三个 ...
- PE结构笔记
提示:前面加*为必须背下来的 DOS头: typedef struct _IMAGE_DOS_HEADER { // DOS .EXE header WORD e_magic; //* Magic n ...
- python_way day12 sqlalchemy,原生mysql命令
python_way day12 sqlalchemy,mysql原生命令 1.sqlalchemy 2.mysql 原生命令 一,sqlalchemy SQLAlchemy本身无法操作数据库,其必 ...
- 《Linux内核设计的艺术》学习笔记(三)Jcond指令
参考书籍:<Assembly Language for x86 Processors (7th Edition)> ◆ JMPI指令: JMPI是x86实模式下的段间跳转指令: BOOTS ...
- url 转码 urlencode和 urldecode
参考网址http://www.t086.com/code/php/function.php-urlencode.php urlencode 将字符串以 URL 编码. 语法: string urlen ...
- 转 cocos2d-x 优化(纹理渲染优化、资源缓存、内存优化)
概述 包括以下5种优化:引擎底层优化.纹理优化.渲染优化.资源缓存.内存优化 引擎优化 2.0版本比1.0版本在算法上有所优化,效率更高.2.0版本使用OpenGl ES 2.0图形库,1.0版本 ...
- 泛型IComparer<T>排序
class Program { static void Main(string[] args) { GetListTest(); } private static void GetListTest() ...
- [转]-Android Studio 快捷键整理分享-SadieYu
文章编辑整理:Android Studio 中文组 - SadieYu Alt+回车 导入包,自动修正 Ctrl+N 查找类 Ctrl+Shift+N 查找文件 Ctrl+Alt+L 格式化代码 ...