最小编辑代价
2016-08-11 20:18
169 查看
#include "iostream" #include "string" #include <algorithm> #include <vector> using namespace std; int findMinCost(string A, int n, string B, int m, int c0, int c1, int c2) { int dp[256][256]; memset(dp, 0, sizeof(int) * 256 * 256); for (int i = 1; i <= n;i++) dp[i][0] = dp[i - 1][0] + c1; for (int j = 1; j <= m; j++) dp[0][j] = dp[0][j - 1] + c0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (A[i - 1] == B[j - 1]) dp[i][j] = dp[i - 1][j - 1]; else dp[i][j] = min(dp[i - 1][j - 1] + c2, min(dp[i][j - 1] + c0, dp[i - 1][j] + c1)); } } return dp [m]; } //测试 int main(int argc, char const *argv[]) { string s1 = "abc", s2 = "adc"; cout << findMinCost(s1, 3, s2, 3, 5, 3, 100) << endl; }
相关文章推荐
- 最小编辑代价---动态规划
- 左神算法 最小编辑代价
- 最小编辑代价(动态规划)
- 最小编辑代价
- 最小编辑代价
- 最小编辑代价(动态规划)
- 最小编辑代价
- 最小编辑代价 动态规划
- #牛客#代码实现:最小编辑代价、最长增长子序列、汉诺塔进阶、单链表相交
- 最小编辑代价
- 最小编辑代价
- 最小编辑代价&&华为OJ 编辑距离&&计算字符串的相似度
- 动态规划系列问题-最小编辑代价
- 【动态规划】最小编辑代价
- godfrey_88 最小编辑代价
- 递归与动态规划---最小编辑代价
- 最小编辑代价(动态规划)
- 最小编辑代价
- poj 3171 dp+线段树(最小代价覆盖全部区间)
- poj 1080 DP 2个串,中间可加‘-’变成长度相同的串,求最小代价