| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
我贴一下吧,求大牛们帮忙看看:In Reply To:是...可我为什么WA啊,我还重敲了一次 Posted by:mostleg at 2005-07-30 12:10:33 #include <cstdio>
#include <cstring>
long l[1001],r[1001];
long upl[1001][1001];
long upr[1001][1001];
long n;
long best[1001][1001];
int main()
{
long i,j,a,b;
while (scanf("%ld",&n)==1)
{
for (i=1;i<=n;i++)
{
scanf("%ld",&l[i]);
}
for (i=1;i<=n;i++)
{
scanf("%ld",&r[i]);
}
memset(upl,0,sizeof(upl));
memset(upr,0,sizeof(upr));
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
if (l[i]==r[j])
{
upl[i][j+1]=j;
upr[j][i+1]=i;
}
else
{
upl[i][j+1]=upl[i][j];
upr[j][i+1]=upr[j][i];
}
}
}
memset(best,0,sizeof(best));
for (i=2;i<=n;i++)
{
for (j=2;j<=n;j++)
{
best[i][j]=best[i-1][j];
if (best[i][j-1]>best[i][j])
best[i][j]=best[i][j-1];
if (l[i]!=r[j])
{
a=upl[i][j];
b=upr[j][i];
if ((a) && (b))
{
if (best[i][j]<best[a-1][b-1]+2)
best[i][j]=best[a-1][b-1]+2;
}
}
}
}
printf("%ld\n",best[n][n]);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator