Longest Common Subsequence - My articles - Publisher - Information Technology
Saturday, 2016-12-03, 10:43 PM
ebooks Programming Computer Science
Welcome Guest | RSS
Site menu
Section categories
My articles [23]
Main » Articles » My articles

Longest Common Subsequence
#include<stdio.h>
#include<string.h>

char line1[100],line2[100];
int LCS(int,int);
int best(int,int);
//int lcsdp[100][100];

void main()
{
int l1,l2;
/* for(int i=0;i<100;++i)
for(int j=0;j<100;++j)
lcsdp[i][j]=-1;*/

//while(gets(line1) && gets(line2))
gets(line1);
gets(line2);
    l1=strlen(line1);
l2=strlen(line2);

printf("%d\n",LCS(l1-1,l2-1));
}

int LCS(int i,int j)
{
if((i<0)||(j<0))return 0;
//if(lcsdp[i][j]>-1)return lcsdp[i][j];
if(line1[i]==line2[j]){
//lcsdp[i][j]=
return LCS(i-1,j-1)+1;
//return lcsdp[i][j];
}
int res1=LCS(i-1,j);
int res2=LCS(i,j-1);
//lcsdp[i][j]=best(res1,res2);
return best(res1,res2);
//return lcsdp[i][j];

return 1;
}

int best(int m,int n)
{
if(m>n)
return m;
else
return n;

return 0;
}




Category: My articles | Added by: Sumrat (2012-03-26)
Views: 294 | Rating: 0.0/0
Total comments: 0
Name *:
Email *:
Code *:
Our poll
Rate my site
Total of answers: 152
Statistics

Total online: 1
Guests: 1
Users: 0
Login form