您的位置:首页 > 其它

hdu----(1950)Bridging signals(最长递增子序列 (LIS) )

2014-09-24 21:43 459 查看

Bridging signals

Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 667 Accepted Submission(s): 443


[align=left]Problem Description[/align]
'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?

//#define LOCAL
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=40005;

int str[maxn],ans[maxn],dp[maxn];
int n,dd;

int LIS(int a[], int n)
{
int i, j,res=0;
for(i=1;i<=n;i++)
ans[i]=inf;
memset(dp,0,sizeof(int)*(n+1));
for(i=1;i<=n;++i)
{

dp[i]=lower_bound(ans+1,ans+n+1,a[i])-ans;
// j=bsearch(c, size, a[i]);  //在已有的序列中进行替换
if(res<dp[i])res=dp[i];
j=i;
if(j>0&&ans[dp[j]]>a[j])
ans[dp[j]]=a[j];
}
return res;
}

int main()
{
#ifdef LOCAL
freopen("test.in","r",stdin);
#endif
int cas;
scanf("%d",&cas);
while(cas--){

scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",str+i);
}
printf("%d\n",LIS(str,n));
}
return 0;
}


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