| ||||||||||
| 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 | |||||||||
TLE,请教出错之处#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int max(int a,int b)
{
return a>b?a:b;
}
int lcs(char* a,char* b,int i,int j)
{
if((i==0)||(j==0))
return 0;
else if(*(a+i-1)==*(b+j-1))
return lcs(a,b,i-1,j-1)+1;
else
return max(lcs(a,b,i-1,j),lcs(a,b,i,j-1));
}
int main()
{
char a[500],b[500];
int len1,len2;
while(cin>>a>>b)
{
len1=strlen(a);
len2=strlen(b);
cout<<lcs(a,b,len1,len2)<<endl;
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator