最长公共子序列LCS
2013-12-10 17:12
148 查看
/* Returns length of LCS for X[0..m-1], Y[0..n-1] */ int lcs( char *X, char *Y, int m, int n ) { int L[m+1][n+1]; int i, j; /* Following steps build L[m+1][n+1] in bottom up fashion. Note that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */ for (i=0; i<=m; i++) { for (j=0; j<=n; j++) { if (i == 0 || j == 0) L[i][j] = 0; else if (X[i-1] == Y[j-1]) L[i][j] = L[i-1][j-1] + 1; else L[i][j] = max(L[i-1][j], L[i][j-1]); } } /* L[m] contains length of LCS for X[0..n-1] and Y[0..m-1] */ return L[m] ; }
相关文章推荐
- HDOJ 1513 Palindrome (最长公共子序列 LCS)
- hdu1159 LCS最长公共子序列
- 算法分析—最长公共子序列(LCS)
- 最长公共子序列(LCS)
- 使用动态规划求解最长公共子序列(LCS)
- 动态规划算法之:最长公共子序列 & 最长公共子串(LCS)
- 【动态规划基础篇】【矩阵取数/最大字段和/最长公共子序列(LCS)/编辑距离/最长上升子序列(LIS)】
- LCS(最长公共子序列)
- 单调递增最长子序列(LIS)&&最长公共子序列(LCS)
- 51nod 最长公共子序列问题(动态规划)(LCS)(递归)
- 51nod 最长公共子序列测试 【LCS+回溯】
- 最长公共子序列(LCS)
- 动态规划--3.最长公共子序列LCS和最长公共子字符串
- LCS-最长公共子序列
- [dp]LCS最长公共子序列
- 1006 最长公共子序列Lcs
- UVA - 10066 The Twin Towers(LCS最长公共子序列)
- 最长公共子序列问题LCS
- 基于动态规划的最长公共子序列实现(LCS)
- 算法学习心得——动态规划法实现最长公共子序列(LCS)