动态规划-最长子序列
递归式: c[i-1][j] 还是 c[i][j-1] 。 代码: int Lcs( string &s1, string &s2, int i, int j, int ** &arr) { if (arr == nullptr ) { arr = new int *[s1.length()+ 1 ]; for ( int i = 0 ; i <= s1.length(); i++) { arr[i] = new int [s2.length()+ 1 ]; } for ( int i = 0 ; i <= s1.length(); i++) { arr[i][ 0 ] = 0 ; for ( int j = 0 ; j <= s2.length(); j++) { arr[ 0 ][j] = 0 ; if (i >= 1 && j >= 1 ) { arr[i][j] = - 1 ; } } } } if (i == 0 || j == 0 ) { arr[i][j] = 0 ; return arr[i][j]; } if (arr[i][j] != - 1 ) { return arr[i][j]; } if (s1[i- 1 ] == s2[j- 1 ]){ arr[i][j]= Lcs(s1, s2, i - 1 , j - 1 ,arr) + 1 ; } else {