@@ -0,0 +1,1483 @@
+// https://www.geeksforgeeks.org/longest-common-subsequence-dp-4/%0Aclass Solution %7B%0A  public static void main(String args%5B%5D) %7B%0A    String one = new String(%22abcdaf%22);%0A    String two = new String(%22acbcf%22);%0A    output(one, two);%0A    System.out.println(%22Expected: 4%22);%0A    int longest_common_subsequence = 0;%0A    longest_common_subsequence = get_longest_common_subsequence(one, two);%0A    System.out.println(%22Output: %22 + longest_common_subsequence);%0A%0A  %7D%0A  private static void output(String one, String two)%7B%0A    System.out.println(%22String One: %22 + one);%0A    System.out.println(%22String Two: %22 + two);%0A  %7D%0A  private static int get_longest_common_subsequence(String one, String two)%7B%0A    int%5B%5D%5B%5D dp = new int%5Bone.length()+1%5D%5Btwo.length()+1%5D;%0A    int max = recursive(dp, one.toCharArray(), two.toCharArray(), 0, 0, 0);%0A    return max;%0A  %7D%0A  private static int recursive(int%5B%5D%5B%5D dp, char%5B%5D one, char%5B%5D two, int i, int j, int max)%7B%0A%0A    if(i == one.length)%7B%0A      return 0;%0A    %7D%0A    if(j == two.length)%7B%0A      return 0;%0A    %7D%0A%0A    if(one%5Bi%5D == two%5Bj%5D)%7B%0A      // dp%5Bi%5D%5Bj%5D = 1 + dp%5Bi+1%5D%5Bj+1%5D;%0A      return 1 + recursive(dp, one, two, i+1, j+1, max);%0A    %7D%0A    else %7B%0A      dp%5Bi%5D%5Bj%5D = Math.max(dp%5Bi-1%5D%5Bj%5D,dp%5Bi%5D%5Bj-1%5D);%0A      return Math.max(recursive(dp, one, two, i+1, j, max), recursive(dp, one, two, i, j+1, max));%0A    %7D%0A    /**%0A    if(dp%5Bi%5D%5Bj%5D %3E max)%7B%0A      max = dp%5Bi%5D%5Bj%5D;%0A    %7D%0A    recursive(dp, one, two, i+1, j, max);%0A    recursive(dp, one, two, i, j+1, max);%0A    return max;%0A    */%0A  %7D%0A%7D%0A

Longest common subsequence