您的位置:首页 > 其它

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

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: