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

TLE,请教出错之处

Posted by lyhypacm at 2009-12-19 21:03:04 on Problem 1458
#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:
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