Edit Distance
来源:互联网 发布:小熊棋牌三网通源码 编辑:程序博客网 时间:2024/06/06 21:04
DP的一题
d[i, j] = 最小值(
d[i-1, j ] + 1, // 刪除
d[i , j-1] + 1, // 插入
d[i-1, j-1] + {0,1} // 替換
class Solution {public: int minDistance(string word1, string word2) { int len1 = word1.size(); int len2 = word2.size(); if(len1 == 0||len2 == 0) return max(len1,len2); vector<vector<int> >f(len1+1 ,vector<int>(len2+1)); for(int i = 0;i<len1+1;i++) f[i][0] = i; for(int i = 0;i<len2+1;i++) f[0][i] = i; for(int i = 1;i<len1+1;i++) for(int j = 1;j<len2+1;j++) f[i][j] = min(f[i-1][j]+1,min(f[i][j-1]+1,f[i-1][j-1]+(word1[i-1]==word2[j-1]?0:1))); return f[len1][len2]; }};
0 0
- edit distance
- Edit Distance
- edit distance
- Edit Distance
- Edit Distance
- Edit Distance
- Edit Distance
- Edit Distance
- Edit Distance
- Edit Distance
- Edit Distance
- Edit Distance
- Edit Distance
- Edit Distance
- Edit Distance
- Edit Distance
- Edit Distance
- Edit Distance
- android The method setOnClickListener(View.OnClickListener)解决办法
- 25个超棒的jQuery日历和日期选取插件
- 文档在线预览
- Android 百度map 初次开发心得
- Linux重要表格整理
- Edit Distance
- 深入了解SQL注入绕过waf和过滤机制
- 2015届校园招聘机考(1)_2178_垃圾短信识别
- WebView.destroy()
- 文件操作之fseek,ftell
- X-Ray 游戏项目总结与反思
- opengl开发微理解
- java 将javaBean写入文本文件
- datagridview 绑定后的操作