hdu 1950 Bridging signals 求最长子序列 ( 二分模板 )
Bridging signals
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4452 Accepted Submission(s): 2769
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.
4
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
Sample Output
3
9
1
4
#include<iostream>
#include<algorithm>
using namespace std;
int a[],lis[];
int t,n;
int main()
{
cin>>t;
while(t--)
{
cin>>n;
for(int i=;i<=n;i++)//因为upper_bound(),所以从1开始方便
{
cin>>a[i];
}
int len=;
for(int i=;i<=n;i++)
{
if(a[i]>lis[len])//严格单调
{
lis[++len]=a[i];
continue;
}
int t=upper_bound(lis,lis+len,a[i])-lis;//返回第一个比a[i]大的数
lis[t]=a[i];
}
cout<<len<<endl;
} return ;
}
hdu 1950 Bridging signals 求最长子序列 ( 二分模板 )的更多相关文章
- HDU 1950 Bridging signals【最长上升序列】
解题思路:题目给出的描述就是一种求最长上升子序列的方法 将该列数an与其按升序排好序后的an'求出最长公共子序列就是最长上升子序列 但是这道题用这种方法是会超时的,用滚动数组优化也超时, 下面是网上找 ...
- HDU 1950 Bridging signals (DP)
职务地址:HDU 1950 这题是求最长上升序列,可是普通的最长上升序列求法时间复杂度是O(n*n).显然会超时.于是便学了一种O(n*logn)的方法.也非常好理解. 感觉还用到了一点贪心的思想. ...
- HDU 1950 Bridging signals(LIS)
最长上升子序列(LIS)的典型变形,O(n^2)的动归会超时.LIS问题可以优化为nlogn的算法. 定义d[k]:长度为k的上升子序列的最末元素,若有多个长度为k的上升子序列,则记录最小的那个最末元 ...
- HDU 1950 Bridging signals (LIS,O(nlogn))
题意: 给一个数字序列,要求找到LIS,输出其长度. 思路: 扫一遍+二分,复杂度O(nlogn),空间复杂度O(n). 具体方法:增加一个数组,用d[i]表示长度为 i 的递增子序列的最后一个元素, ...
- HDU 1950 Bridging signals
那么一大篇的题目描述还真是吓人. 仔细一读其实就是一个LIS,还无任何变形. 刚刚学会了个二分优化的DP,1A无压力. //#define LOCAL #include <iostream> ...
- 求最长子序列(非连续)的STL方法 - 洛谷P1020 [NOIP1999 普及组] 导弹拦截
先给出例题:P1020 [NOIP1999 普及组] 导弹拦截 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 大佬题解:P1020 [NOIP1999 普及组] 导弹拦截 - 洛谷 ...
- hdoj 1950 Bridging signals【二分求最大上升子序列长度】【LIS】
Bridging signals Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- (hdu)1950 Bridging signals(最长上升子序列)
Problem Description 'Oh no, they've done it again', cries the chief designer at the Waferland chip f ...
- HDU 6625 three arrays 求两个序列异或最小值的排列(一个可以推广的正解
目录 题意: 解析 原题描述 字典树动态求Mex @(hdu 6625求两个序列异或最小值的排列) 题意: \(T(100)\)组,每组两个长度为\(n(100000)\)的排列,你可以将\(a[]\ ...
随机推荐
- Python学习笔记之基础篇(四)列表与元祖
#### 列表 li = ['alex','wusir','egon','女神','taibai'] ###增加的3种方法 ''' # append li.append('日天') li.append ...
- Java异常的限制
Java异常的限制 我在看JAVA编程思想,讲到异常的限制,看的代码和解释,非常的难看下去,直接写了他的代码. java编程思想关于异常限制的逻辑 它以棒球比赛为例子. 定义了Inning(一局比赛) ...
- c++存储区域
来自:https://www.cnblogs.com/simonote/articles/3146038.html 在C++中,内存分成5个区,他们分别是堆.栈.自由存储区.全局/静态存储区和常量存储 ...
- 第1节 storm编程:4、storm环境安装以及storm编程模型介绍
dataSource:数据源,生产数据的东西 spout:接收数据源过来的数据,然后将数据往下游发送 bolt:数据的处理逻辑单元.可以有很多个,基本上每个bolt都处理一部分工作,然后将数据继续往下 ...
- DeprecationWarning:'open()' is deprecated in mongoose>=4.11.0,use 'openUri()' instead or set the 'useMongoClient' option if using 'connect()' or 'createConnection'
mongoose.connect('mongodb://localhost/test');报错:(node:2752) DeprecationWarning: `open()` is deprecat ...
- PostGIS 常用函数中文介绍说明
1.OGC标准函数 管理函数: 添加几何字段 AddGeometryColumn(, , , , , ) 删除几何字段 DropGeometryColumn(, , ) 检查数据库几何字段并在geom ...
- nested exception is javax.management.InstanceAlreadyExistsException: webservice:name=statFilter,type=StatFilter
Caused by: org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [ ...
- docker学习笔记-03:docker的镜像原理
镜像是一种轻量级.可执行的独立软件包,用来打包软件运行环境和基于运行环境开发的软件.它包含运行某个环境所需的所有内容,包括代码.库.环境变量和配置文件. 一.镜像是什么 (一).联合文件系统(Unio ...
- mysql批量插入更新操作
//添加关联赠品(确定) public function addGiveGoods($ids,$child,$parent_sku_no){ $license=new LicenseModel(); ...
- 018.CI4框架CodeIgniter数据库操作之:Delete删除一条数据
01. 在Model中写数据库操作语句,代码如下: <?php namespace App\Models\System; use CodeIgniter\Model; class User_mo ...