51nod1183 编辑距离
2016-07-20 20:45
190 查看
链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1183
题意:中文题。
分析:设dp[i][j]表示s前i个字符和t前j个字符的编辑距离。基础dp,注意边界dp[i][0]和dp[0][i]。
代码:
#include<map> #include<set> #include<cmath> #include<queue> #include<bitset> #include<math.h> #include<vector> #include<string> #include<stdio.h> #include<cstring> #include<iostream> #include<algorithm> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int N=1010; const int mod=100000000; const int MOD1=1000000007; const int MOD2=1000000009; const double EPS=0.00000001; typedef long long ll; const ll MOD=1000000007; const int MAX=1000000010; const ll INF=1ll<<55; const double pi=acos(-1.0); typedef double db; typedef unsigned long long ull; char s ,t ; int dp ; int main() { int i,j,les,let; scanf("%s", s); scanf("%s", t); les=strlen(s);let=strlen(t); for (i=1;i<=let;i++) dp[i][0]=dp[0][i]=i; for (i=1;i<=les;i++) for (j=1;j<=let;j++) if (s[i-1]==t[j-1]) dp[i][j]=min(dp[i-1][j-1],min(dp[i-1][j]+1,dp[i][j-1]+1)); else dp[i][j]=min(dp[i-1][j-1]+1,min(dp[i-1][j]+1,dp[i][j-1]+1)); printf("%d\n", dp[les][let]); return 0; }
相关文章推荐
- Search a 2D Matrix
- css之伪类选择器:before :after(::before ::after)
- abelkhan编译文档
- HDU 4990 Reading comprehension
- C语言地址相减
- 输入整型数组和排序标识,对其元素按照升序或降序进行排序
- Saving HDU(贪心)
- STL-vector-size
- 计蒜客-泥塑客
- 7.20总结
- bzoj 3884 上帝与集合的正确用法 指数循环节
- 关于浮动清除的一些小感悟,4种方法清除浮动
- unity 类的序列化
- 【HD 1222】Wolf and Rabbit
- Matlab Kalman滤波
- Nginx负载均衡配置实例详解
- AngularJS 笔记——$on、$emit和$broadcast的使用与区别
- 【POJ 1364】King(差分约束系统)
- HDOJ 4548 美素数
- PostgreSQL 物流调度算法探索 - 基于PostGIS/pgrouting/机器学习