Saturday, 7 September 2013

how to apply longest common subsequnce algrithm for bigger string

how to apply longest common subsequnce algrithm for bigger string

how to apply longest common subsequence of bigger string such as 600000
size...is there any way to do it in dp?? i have done this for shorter
strings... #include #include #include #include using namespace std; int
dp[1005][1005]; char a[1005],b[1005];
int lcs(int x,int y)
{
if(x==strlen(a)||y==strlen(b))
return 0;
if(dp[x][y]!=-1)
return dp[x][y];
else if(a[x]==b[y])
dp[x][y]=1+lcs(x+1,y+1);
else
dp[x][y]=max(lcs(x+1,y),lcs(x,y+1));
return dp[x][y];
}
int main()
{
while(gets(a)&&gets(b))
{
memset(dp,-1,sizeof(dp));
int ret=lcs(0,0);
printf("%d\n",ret);
}
}

No comments:

Post a Comment