题目大意:

给你两个字符串A,B,和以下三种操作:

1.删除一个字符

2.插入一个字符

3.把一个字符改变成另一个字符

求使A变成B所需要的最少的操作;

我刚开始的思路是以为求出最长公共子序列,然后对比A,B的长度做加减,不过WA了一发,

后来想,,可以在这三种操作上做文章,

A[i]==B[j]时

  dp[i][j]=dp[i-1][j-1];

A[i]!=B[j]时:分三种情况

1.插入字符:dp[i][j]=dp[i-1][j]+1;

2.删除字符:dp[i][j]=dp[i][j-1]+1;

3.替换字符:dp[i][j]=dp[i-1][j-1]+1;

代码如下:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f;
#define F(x,y) for(x=0;x<=y;x++)
const int maxn=2e3+;
int dp[maxn][maxn];
int main()
{
string a,b;
while(cin>>a>>b){
memset(dp,,sizeof(dp));
int i,j;
int lena=a.length(),lenb=b.length();
F(i,lena) dp[i][]=i;
F(i,lenb) dp[][i]=i;
F(i,lena)
F(j,lenb)
if(a[i-]==b[j-])
dp[i][j]=dp[i-][j-];
else
dp[i][j]=min(dp[i-][j-],min(dp[i-][j],dp[i][j-]))+;
printf("%d\n",dp[lena][lenb]);
}
return ;
}

这题代码稍微一改,就是  不连续的最长公共子序列http://acm.hdu.edu.cn/showproblem.php?pid=1159;

Edit Distance FZU-1434的更多相关文章

  1. [LeetCode] One Edit Distance 一个编辑距离

    Given two strings S and T, determine if they are both one edit distance apart. 这道题是之前那道Edit Distance ...

  2. [LeetCode] Edit Distance 编辑距离

    Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2 ...

  3. Edit Distance

    Edit Distance Given two words word1 and word2, find the minimum number of steps required to convert  ...

  4. 编辑距离——Edit Distance

    编辑距离 在计算机科学中,编辑距离是一种量化两个字符串差异程度的方法,也就是计算从一个字符串转换成另外一个字符串所需要的最少操作步骤.不同的编辑距离中定义了不同操作的集合.比较常用的莱温斯坦距离(Le ...

  5. LintCode Edit Distance

    LintCode Edit Distance Given two words word1 and word2, find the minimum number of steps required to ...

  6. stanford NLP学习笔记3:最小编辑距离(Minimum Edit Distance)

    I. 最小编辑距离的定义 最小编辑距离旨在定义两个字符串之间的相似度(word similarity).定义相似度可以用于拼写纠错,计算生物学上的序列比对,机器翻译,信息提取,语音识别等. 编辑距离就 ...

  7. [UCSD白板题] Compute the Edit Distance Between Two Strings

    Problem Introduction The edit distinct between two strings is the minimum number of insertions, dele ...

  8. 动态规划 求解 Minimum Edit Distance

    http://blog.csdn.net/abcjennifer/article/details/7735272 自然语言处理(NLP)中,有一个基本问题就是求两个字符串的minimal Edit D ...

  9. One Edit Distance

    Given two strings S and T, determine if they are both one edit distance apart. 分析:https://segmentfau ...

  10. 【leetcode】Edit Distance

    Edit Distance Given two words word1 and word2, find the minimum number of steps required to convert  ...

随机推荐

  1. arcgis for javascript 添加featurelayer,设置地图最大最小等级

    转自原文arcgis for javascript 添加featurelayer,设置地图最大最小等级 var map; var livingCenter; var livingCenterUrl = ...

  2. Python标准库:内置函数range(stop) range(start, stop[, step])

    本函数是产生一系列序列的数组,返回迭代子.參数stop是终止的数字:參数start是指明開始数列開始值:參数step是数列之间的差值. 因此这个函数就是产生以start为起点.以stop为终点,以st ...

  3. 区间最小值 线段树 (2015年 JXNU_ACS 算法组暑假第一次周赛)

    区间最小值 Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Submiss ...

  4. ZOJ2724_Windows Message Queue(STL/优先队列)

    解题报告 题意: 看输入输出就非常明确. 思路: 优先队列. #include <algorithm> #include <iostream> #include <cst ...

  5. 自己定义控件三部曲之动画篇(七)——ObjectAnimator基本使用

    前言: 假如生活欺骗了你, 不要悲伤,不要心急! 忧郁的日子里须要镇静: 相信吧,快乐的日子终将会来临! 心儿永远向往着未来: 如今却常是忧郁. 一切都是瞬息,一切都将会过去: 而那过去了的,就会成为 ...

  6. 杭电1879继续畅通project

    继续畅通project Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  7. 国内物联网平台初探(八):中移物联网开放平台OneNet

    平台定位 OneNET是中移物联网有限公司搭建的开放.共赢设备云平台,为各种跨平台物联网应用.行业解决方案,提供简便的云端接入.存储.计算和展现,快速打造物联网产品应用,降低开发成本. IoT Paa ...

  8. JS垃圾回收——和其他语言一样,JavaScript 的 GC 策略也无法避免一个问题:GC 时,停止响应其他操作,这是为了安全考虑

    JavaScript 内存管理 & 垃圾回收机制 标记清除 js 中最常用的垃圾回收方式就是标记清除.当变量进入环境时,例如,在函数中声明一个变量,就将这个而变量标记为“进入环境”.从逻辑上讲 ...

  9. 11.修改WSDL文档

    http://localhost:8077/person?wsdl可以由你来控制的.拿Person这个例子来说.

  10. js设计模式-享元模式

    享元模式实际上是一种优化模式,目的在于提高系统的性能和代码的效率. 使用享元模式的条件:最重要的条件是网页中必须使用了大量资源密集型对象,如果只会用到了少许这类对象,那么这种优化并不划算.第二个条件是 ...