B - Bridging signals (LIS)

2023-10-20 23:38
文章标签 lis signals bridging

本文主要是介绍B - Bridging signals (LIS),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

点击打开链接


B - Bridging signals

 


'Oh 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.
Input
On 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.
Output
For each test scenario, output one line containing the maximum number of signals which may be routed on the silicon surface without crossing each other.
Sample Input
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



错误代码(一组数据行,怎么实现多组数据输入?)

Select Code
#include <stdio.h>
#include <cstring>
#include <algorithm>
#define INF 0x3f3f3f
using namespace std;
int dp[30020],a[30020];
int main()
{int n;scanf("%d",&n);while(n--){int m;scanf("%d",&m);for(int i=0; i<m ; i++){scanf("%d",&a[i]);dp[i]=INF;}for(int i=0; i<m; i++)*lower_bound(dp,dp+n,a[i])=a[i];	//优化 printf("%d\n",lower_bound(dp,dp+m,INF)-dp);	}	return 0;
}
正确代码

Select Code
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std; int a[41000];
int main()
{int N,n,i,j,t;scanf("%d",&N);while(N--){scanf("%d",&n);scanf("%d",&t);a[0]=t;int top=1;for(i=1; i<n; i++){scanf("%d",&t);if(t>=a[top-1])a[top++]=t;else{int z=0,q=top-1;while(z<=q){int mid=(z+q)/2;if(a[mid]<t)z=mid+1;elseq=mid-1;}a[z]=t;}}printf("%d\n",top);}return 0;
}




这篇关于B - Bridging signals (LIS)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/250424

相关文章

【UVA】10534 - Wavio Sequence(LIS最长上升子序列)

这题一看10000的数据量就知道必须用nlog(n)的时间复杂度。 所以特意去看了最长上升子序列的nlog(n)的算法。 如果有2个位置,该位置上的元素为A[i]和A[j],并且他们满足以下条件: 1.dp[i] = dp[j]    (dp[x]代表以x结尾的最长上升子序列长度) 2.A[i] < A[j] 3.i < j 那么毫无疑问,选择dp[i] 一定优于选择dp[j] 那么

医院检验系统LIS源码,LIS系统的定义、功能结构以及样本管理的操作流程

本文将对医院检验系统LIS进行介绍,包括LIS系统的定义、功能结构以及样本管理的操作流程方面。 LIS系统定义 LIS系统(Laboratory Information System)是一种专门为临床检验实验室开发的信息管理系统,其主要功能包括实验室信息管理、样本管理、检验结果管理、质量控制管理、数据分析等。其主要作用是管理医院实验室的各项业务,包括样本采集、检验、结果录入和报告生成等。Li

LCS转为LIS

(1) 先将所有数列排序。     第一维由小到大,当第一维相等时,第二维由大到小。   (排序规则亦可改成以第二个维度为主,最后则是找第一个维度的1DLIS。)       a     a    a     b     b    a     a     a    c     d   (0,6) (0,3) (0,2) (1,4) (1,1)(2,6) (2,3) (2,2) (3,5) (4,

uva10534(DP之LIS的应用 )

题意:在给出的序列中找到一个长度为奇数的序列,且序列前半段严格单调递增,后半段严格单调递减。 解答:进行两次LIS,一次正向,一次逆向,LIS选用Nlogn的算法 /*Solve:*/#include<iostream>#include<algorithm>#include<map>#include<cstdio>#include<cstdlib>#include<vector>

HDU 5748 (Bellovin LIS)

题目连接 nlogn求一下LIS 就好了 #include<cstdio>#include<algorithm>#include<iostream>using namespace std;#define cl(a,b) memset(a,b,sizeof(a))#define LL long long#define pb push_back#define gcd __gcd#de

F. LIS on Tree 树上根路径LIS

1 关于lower_bound // 12345 查4 应该放在4 。而不是5的位置。。所以不是uppper。 //如果1235 查4 。可以优化5 。 2 关于 ans[u] = max(j, ans[p]); 维护一个max 一定从(premax,cur)中选出来的。 3 关于 memset(st, 0x3f, sizeof st); 这个和st + 1, st + n + 1 。。我们二分选

POJ 2533 LIS N2

状态转移方程  dp[i]=max(dp[i],dp[j]+1); dp[i]为以第i个数结尾的能得到的最长的上升子序列。1<=j<i。 这个题目注意a[i]可能为0,因此要注意初始化a[0]=-1; http://poj.org/problem?id=2533 Longest Ordered Subsequence Time Limit: 2000MSMemory Limit: 6

HDU 5532 Almost Sorted Array (2015ACM/ICPC长春LIS)

【题目链接】:click here~~ 【题目描述】: Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 272    Accepted Submission(s): 132

HDU 1950 Bridging signals (DP)

题目地址:HDU 1950 这题是求最长上升序列,但是普通的最长上升序列求法时间复杂度是O(n*n),显然会超时。于是便学了一种O(n*logn)的方法。也很好理解。感觉还用到了一点贪心的思想。 具体的见这篇博客吧,写的很通俗易懂。传送门 代码如下: #include <iostream>#include <cstdio>#include <string>#include <cs

LIS(最长递增子序列)和LCS(最长公共子序列)的总结

LIS(最长递增子序列)和LCS(最长公共子序列)的总结 最长公共子序列(LCS):O(n^2) 两个for循环让两个字符串按位的匹配:i in range(1, len1) j in range(1, len2) s1[i - 1] == s2[j - 1], dp[i][j] = dp[i - 1][j -1] + 1; s1[i - 1] != s2[j - 1], dp[