| ||||||||||
| 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 <iostream>
#include <string>
using namespace std;
string s1, s2;
int l1, l2;
int LCS(int x, int y)
{
if (x >= l1 || y >= l2)
return 0;
if (s1[x] == s2[y])
return 1+LCS(x+1, y+1);
return max(LCS(x, y+1), LCS(x+1, y));
}
int main()
{
while (cin>>l1)
{
cin>>s1>>l2>>s2;
cout<<max(l1,l2)-LCS(0, 0)<<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