POJ_1631_Bridging_Signals_(动态规划,LIS)
2016-04-26 09:53
316 查看
描述
http://poj.org/problem?id=1631
铁路左右相连,要求去掉一些边,使得剩下的边不交叉,求剩余边数的最大值.
Bridging signals
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 12652 | Accepted: 6898 |
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 crossing each other, is imminent. Bearing in mind that there may be thousands 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?#include<cstdio> #include<algorithm> #define read(a) a=getnum() #define for1(i,a,n) for(int i=(a);i<=(n);i++) using namespace std; const int maxn=40005,INF=0x7fffffff; int q,n; int a[maxn],dp[maxn]; inline int getnum(){ int r=0,k=1;char c;for(c=getchar();c<'0'||c>'9';c=getchar()) if(c=='-') k=-1;for(;c>='0'&&c<='9';c=getchar()) r=r*10+c-'0'; return r*k; } int bsearch(int l,int r,int v) { while(l<r) { int m=l+(r-l)/2; if(dp[m]>=v) r=m; else l=m+1; } return l; } void solve() { for1(i,1,n+1) dp[i]=INF; for1(i,1,n) { int idx=bsearch(1,n,a[i]); dp[idx]=a[i]; } int ans=bsearch(1,n+1,INF)-1; printf("%d\n",ans); } void init() { read(q); while(q--) { read(n); for1(i,1,n) read(a[i]); solve(); } } int main() { #ifndef ONLINE_JUDGE freopen("bridge.in","r",stdin); freopen("bridge.out","w",stdout); #endif init(); #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout); system("bridge.out"); #endif return 0; }View Code
相关文章推荐
- 如何从零开始搭建一个技术平台
- Python系列(一)转义字符
- Java语法糖4:内部类
- Python多进程并发(multiprocessing)
- Eclipse中jsp,html代码自动排版太丑怎么办?!改改就好了!
- IOS(objective-c)实现md5加密(32位小写)的工具类
- Oracle正则表达式使用介绍
- GCD定时器
- SqlDataReader
- Toolbar标题栏
- 用IEDA开发WEB项目发生的java.lang.NoClassDefFoundError解决方法
- 隐藏UITableView多余的分割线
- Coursera机器学习第8周作业
- HDU 1520 Anniversary party 树形dp
- top.location != self.location
- Photoshop打造喷溅水墨效果
- Python多线程学习
- 北京联通DNS
- Delphi COM编程技术三类型库
- iOS 相机调用相册打开及图片头像的上传到服务器详解