Longest Common Subsequence using Dynamic Programming(Bottom-Up Approach)
#include<iostream>
#include<limits.h>
#include<string.h>
using namespace std;
string x,y;
int main(){
char *x=”rajat”,*y=”jadam”;
int xsize=strlen(x);
int ysize=strlen(y);
int L[xsize+1][ysize+1];
for(int i=0;i<=xsize;i++){
for(int j=0;j<=ysize;j++){
if(i==0||j==0){
L[i][j]=0;
}
}
}
for(int i=1;i<=xsize;i++){
for(int j=1;j<=ysize;j++){
if(x[i-1]==y[j-1]){
L[i][j]=1+L[i-1][j-1];
cout<<L[i][j]<<”(“<<i<<”,”<<j<<”)\t”;
}
else{
if(L[i-1][j]>L[i][j-1]){
L[i][j]=L[i-1][j];
}
else{
L[i][j]=L[i][j-1];
}
}
}
}
cout<<”\n\n”;
for(int i=0;i<=xsize;i++){
for(int j=0;j<=ysize;j++){
cout<<L[i][j]<<”\t”;
}
cout<<”\n”;
}
}