Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:我贴一下吧,求大牛们帮忙看看:

Posted by frkstyc at 2005-07-30 13:09:47
In Reply To:我贴一下吧,求大牛们帮忙看看: Posted by:mostleg at 2005-07-30 12:16:27
> #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;
                                                    ~~~~j
> 					upr[j][i+1]=i;
                                                    ~~~~i
> 				}
> 				else
> 				{
> 					upl[i][j+1]=upl[i][j];
                                                    ~~~~j       ~~j-1
> 					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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator