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 cmdlinux at 2011-04-13 22:32:20 on Problem 1458
In Reply To:查来查去查了一年,还是不知道哪里错了!! Posted by:Algor at 2010-04-15 22:05:38
附上改掉以后的代码,希望对你有帮助。
#include<iostream>
using namespace std;
#define N 1000
char str1[N],str2[N];
int rec[N][N];
int LCS()
{
	int l1,l2,i,j;
	l1=strlen(str1);
	l2=strlen(str2);
	memset(rec,0,sizeof(rec));
	for(i=1;i<=l1;i++)
	{
		for(j=1;j<=l2;j++)
		{
			if(str1[i-1]==str2[j-1])
			{
				if(rec[i][j]<rec[i-1][j-1]+1)
					rec[i][j]=rec[i-1][j-1]+1;
			}
			if(rec[i][j]<rec[i-1][j])
				rec[i][j]=rec[i-1][j];
			if(rec[i][j]<rec[i][j-1])
				rec[i][j]=rec[i][j-1];
		}
	}
	return rec[l1][l2];
}
int main()
{
	while(scanf("%s%s",str1,str2)!=EOF)
		printf("%d\n",LCS());
	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