Can Any one can formulate Memoized Solution of this Recursive Solution

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
static char[]word;
static char x;
static int[][][] matrix;
public static void main(String[] args) throws Exception {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int test =  getInt(br.readLine());

    while (test-->0){
         x =  br.readLine().charAt(0);
         word = br.readLine().toCharArray();
             matrix= new int[word.length][word.length][2];

             for(int i=0;i<word.length;i++){
                 for(int j=0;j<word.length;j++){
                     matrix[i][j][0]=-1;
                      matrix[i][j][1]=-1;
                 }
             }
        System.out.println(solvePalindroimic(0,word.length-1,false));
    }
}
//dcbabcd
public static int solvePalindroimic(int i,int j, boolean isTrue){//Recursive Solution
    if(i>j){// 0,0,false //1 5 false
        return 0;
    }


    if(i==j){
       if(isTrue==true ||(isTrue==false &&word[i]==x)){
           return 1;
       }
       else{
           return 0;
       }
    }
    boolean res = word[i]==x?true:isTrue;//0 , 0 ,false res  =false//1 ,1 res  =false
    int ans = 0;

    if(word[i]==word[j]){


        ans= solvePalindroimic(i+1,j-1,res);//solve(1,5,false)
        if(ans==0){
            return 0;
        }
        else{
            return ans+2;
        }

    }
          ans  =Math.max(solvePalindroimic(i,j-1,res),solvePalindroimic(i+1,j,word[j]==x?true:isTrue));
    if(ans==0){
        return 0;
    }
    else{
        return ans;
    }


}

public static int getInt(String s){
return Integer.parseInt(s);
}
}

What Problem is find largest Palindromic Subsequence having atleast one character c mentioned in Que