HDU 1950 POJ 1631 Bridging signals【LIS,二分优化】
来源:互联网 发布:mac打开侧边栏快捷键 编辑:程序博客网 时间:2024/05/22 16:54
Bridging signals
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2049 Accepted Submission(s): 1356
Problem Description
'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.
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
4642631510234567891018876543219589231746
Sample Output
3914
Source
NWERC2003
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1950
LIS模板题,二分优化
AC代码:
#include <cstdio>#include <cstring>#include <iostream>using namespace std;const int maxn=40000+5;int a[maxn];int dp[maxn];int n;int BinarySearch(int size,int k){ int l=1,r=size; while(l<=r) { int mid=(l+r)>>1; if(k>dp[mid]) l=mid+1; else r=mid-1; } return l;}int LIS(){ int ans=1,j; dp[1]=a[1]; for(int i=2;i<=n;i++) { if(a[i]<=dp[i]) j=1; else if(a[i]>dp[ans]) j=++ans; else j=BinarySearch(ans,a[i]); dp[j]=a[i]; } for(int i=0;i<=ans;i++) cout<<dp[i]<<" "; cout<<endl; return ans;}int main(){ int T; cin>>T; while(T--) { cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; memset(dp,0,sizeof(dp)); cout<<LIS()<<endl; } return 0;}
尊重原创,转载请注明出处:http://blog.csdn.net/hurmishine
0 0
- HDU 1950 POJ 1631 Bridging signals【LIS,二分优化】
- Poj 1631 && Hdu 1950 Bridging signals【LIS】
- [POJ](1631)Bridging signals ---- LIS+O(nlogn)优化(二分)
- POJ 1631 Bridging signals(LIS+二分)
- poj 1631 || hdu 1950 Bridging signals(动态规划:LIS)
- POJ 1631 && HDU 1950 Bridging signals(LIS)
- [二分优化] hdu 1950 Bridging signals
- POJ 1631 Bridging signals(LIS)
- poj-1631Bridging signals(LIS)
- HDU 1950 Bridging signals (LIS)
- HDU 1950 - Bridging signals(LIS)
- Poj 1631 Bridging signals(二分+DP 解 LIS)
- POJ 1631 Bridging signals(LIS 二分 快速方法)
- hdoj--1950--Bridging signals(二分查找+LIS)
- hdoj 1950 Bridging signals (LIS+二分)
- POJ 1631 / HDU 1950 / ZOJ 1986 / Northwestern Europe 2003 Bridging signals (DP&LIS)
- poj 1631(Bridging signals LIS)nlogn
- poj - 1631 - Bridging signals(LIS)
- JdbcUtil 链接,【更新、插入、删除】,查询,释放
- Java NIO Pipe
- hbase的常用操作
- 本博客不在更新了
- Day52、单行函数、日期类型和常用的日期函数、多表查询(表连接)、内连接、外连接
- HDU 1950 POJ 1631 Bridging signals【LIS,二分优化】
- 【Day33】Apache服务器的负载平衡
- Java NIO vs. IO
- 104. Maximum Depth of Binary Tree (二叉树最大深度)
- HUE3.10本地安装
- drawText的坐标问题
- 三种方式记录bash输出的内容
- HDOJ 1874 畅通工程续(最短路)
- CF 3D Least Cost Bracket Sequence