#include<iostream>
#include<string.h>
int count=0;
using namespace std;
int max(int a,int b)
{
return (a>b)?a:b;
}
int lcs(char *x,char*y ,int m,int n)
{
int l[m+1][n+1];
int i,j;
for( i=0;i<=m;i++)
{
for(j=0;j<=n;j++)
{
if(i==0 || j==0)
l[i][j]=0;
else if(x[i-1]==y[j-1])
l[i][j]=l[i-1][j-1]+1;
else
l[i][j] =max(l[i-1][j], l[i][j-1]);
}
}
return l[m][n];
}
int main()
{
char x[]="AGGTAB";
char y[]="GXTXAYB";
int m=strlen(x);
int n=strlen(y);
cout<<"The Length Of the Longest Common Subsequence Is : "<<lcs(x,y,m,n);
}
The above program is for finding the Largest Common Subsequence solution using dynamic programming . I am able to calculate the length of the LCS but i am unable to deduce the logic for finding the total no. of comparisons the system will make to find the lcs .
I want to find the total no. of comparisons and to print it using a global count variable . Could someone help me out?