How can i optimize this code. facing timelimit error

Question:

LCS WITH 3 STRINGS
Given 3 strings ,the task is to find the longest common sub-sequence in all three given sequences.

Input Format:
First line contains first string . Second line contains second string. Third line contains the third string.

Constraints:
The length of all strings is |s|< 200

Output Format
Output an integer denoting the length of longest common subsequence of above three strings.

Sample Input
GHQWNV
SJNSDGH
CPGMAH
Sample Output
2

attempt :
https://ide.codingblocks.com/s/49588

passing only the first test case.

Hey Manal, you have taken the array of size 100 but its given in the constraints that length of string |s|<200. To optimize the solution you can use the bottom up approach also for this problem.

it is difficult to write bottom up code when their are 3 variables. could you help me with a pseudo code and this code still shows time limit error after changing limits

Yes sure, here I am sharing the code snippet with you to understand the bottom up approach for this problem
Here the following steps build L[m+1][n+1][o+1] in bottom up fashion. L[i][j][k] contains length of LCS of X[0…i-1] and Y[0…j-1] and Z[0…k-1].

		for (int i=0; i<=m; i++)
		{
			for (int j=0; j<=n; j++)
			{
				for (int k=0; k<=o; k++)
				{
					if (i == 0 || j == 0||k==0)
						L[i][j][k] = 0;
	
					else if (X.charAt(i - 1) == Y.charAt(j - 1) 
								&& X.charAt(i - 1)==Z.charAt(k - 1))
						L[i][j][k] = L[i-1][j-1][k-1] + 1;
	
					else
						L[i][j][k] = Math.max(Math.max(L[i-1][j][k],
											L[i][j-1][k]),
										L[i][j][k-1]);
				}
			}
		}

import java.util.*;
public class Main {
static int dp[][][]=new int[220][220][220];
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
String str1=sc.next();
String str2=sc.next();
String str3=sc.next();
int m=str1.length();
int n=str2.length();
int o=str3.length();
System.out.println(lcs(str1,str2,str3,m,n,o));
}
public static int lcs(String str1,String str2,String str3,int m,int n,int o){
if(m==0 || n==0 || o==0){
return 0;
}
String ros1=str1.substring(1);
String ros2=str2.substring(1);
String ros3=str3.substring(1);
if(dp[m-1][n-1][o-1]!=0){
return dp[m-1][n-1][o-1];
}
if(str1.charAt(0)==str2.charAt(0) && str2.charAt(0)==str3.charAt(0)){
dp[m-1][n-1][o-1]=1+lcs(ros1,ros2,ros3,m-1,n-1,o-1);
return dp[m-1][n-1][o-1];
}
else{
int f1=lcs(ros1,str2,str3,m-1,n,o);
int f2=lcs(str1,ros2,str3,m,n-1,o);
int f3=lcs(str1,str2,ros3,m,n,o-1);
dp[m-1][n-1][o-1]=Math.max(Math.max(f1,f2),f3);
return dp[m-1][n-1][o-1];
}

}

}

Sir/Mam it is showing TLE with memoization …can u tell what is the problem with the code???