| ||||||||||
| 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 | |||||||||
附上代码,求助!!#include <stdio.h>
#include <string.h>
char str1[501], str2[501];
int len1, len2;
char arr[501][501];
int getmax(int, int);
int
main(int argc, char *argv[])
{
int i, j;
while ( scanf("%s%s", str1, str2) == 2 )
{
len1 = strlen(str1);
len2 = strlen(str2);
for ( i = 0; i <= len1; ++i )
for ( j = 0; j <= len2; ++j )
arr[i][j] = -1;
printf("%d\n", getmax(len1, len2));
}
return 0;
}
int
getmax(int i, int j)
{
int x, y;
if ( arr[i][j] != -1 )
return arr[i][j];
if ( i == 0 || j == 0 )
arr[i][j] = 0;
else
{
if ( str1[i-1] == str2[j-1] )
arr[i][j] = getmax(i-1, j-1) + 1;
else
{
x = getmax(i-1, j);
y = getmax(i, j-1);
arr[i][j] = x > y ? x : y;
}
}
return arr[i][j];
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator