src/com/michaelho/DynamicProgramming/DP1.java
/**
         * The recursive function used to find LCS.
         *
         * @param s1   The first string to be calculated for longest increasing subsequence.
         * @param s2   The second string to be calculated for longest increasing subsequence.
         * @param idx1 The index of the first string.
         * @param idx2 The index of the second string.
         * @return int The results of calculation.
         */
The recursive function used to find LCS.
@param s1   The first string to be calculated for longest increasing subsequence.
@param s2   The second string to be calculated for longest increasing subsequence.
@param idx1 The index of the first string.
@param idx2 The index of the second string.
@return int The results of calculation.
The recursive function used to find LCS . @param s1 The first string to be calculated for longest increasing subsequence . @param s2 The second string to be calculated for longest increasing subsequence . @param idx1 The index of the first string . @param idx2 The index of the second string . @return int The results of calculation .
private int dpFindLongestLength(String s1, String s2, int idx1, int idx2) {
            if (idx1 < 0 || idx2 < 0) {
                return 0;
            }
            if (s1.charAt(idx1) == s2.charAt(idx2))
                return 1 + dpFindLongestLength(s1, s2, idx1 - 1, idx2 - 1);
            else
                return Math.max(dpFindLongestLength(s1, s2, idx1, idx2 - 1),
                        dpFindLongestLength(s1, s2, idx1 - 1, idx2));
        }
private int dpFindLongestLength ( String s1 , String s2 , int idx1 , int idx2 ) { if ( idx1 < 0 || idx2 < 0 ) { return 0 ; } if ( s1 . charAt ( idx1 ) == s2 . charAt ( idx2 ) ) return 1 + dpFindLongestLength ( s1 , s2 , idx1 - 1 , idx2 - 1 ) ; else return Math . max ( dpFindLongestLength ( s1 , s2 , idx1 , idx2 - 1 ) , dpFindLongestLength ( s1 , s2 , idx1 - 1 , idx2 ) ) ; }
The recursive function used to find LCS.
The recursive function used to find LCS .