| ||||||||||
| 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 | |||||||||
Re:查来查去查了一年,还是不知道哪里错了!!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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator