51nod 1183 编辑距离
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1183.
题意不再赘述。
分析:大概和LCS差不多的吧 但是我用LCS转换貌似错了
搜的网上的题解 大概就是 如果(dp[i-1][j-1] dp[i-1][j] dp[i][j-1])转移过来 注意到 如果s[i] == p[j]的情况可以不用+1
#include<bits/stdc++.h>
using namespace std;
char s[],p[];
int dp[][]; int main()
{
scanf("%s %s",s+,p+);
int L1=strlen(s+),L2=strlen(p+);
for(int i=;i<=L1;i++)
dp[i][] = i;
for(int j=;j<=L2;j++)
dp[][j] =j;
for(int i=;i<=L1;i++)
{
for(int j=;j<=L2;j++)
{
if(s[i] == p[j])
dp[i][j] = dp[i-][j-];
else
dp[i][j] = dp[i-][j-]+;
dp[i][j] = min(dp[i][j],min(dp[i-][j],dp[i][j-])+);
}
//printf("\n");
}
printf("%d",dp[L1][L2]);
}
51nod 1183 编辑距离的更多相关文章
- 51nod 1183 编辑距离(dp)
题目链接:51nod 1183 编辑距离 #include<cstdio> #include<cstring> #include<algorithm> using ...
- 51nod 1183 - 编辑距离 - [简单DP][编辑距离问题][Levenshtein距离问题]
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1183 编辑距离,又称Levenshtein距离(也叫做Edi ...
- 51nod 1183 编辑距离【线性dp+类似最长公共子序列】
1183 编辑距离 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 编辑距离,又称Levenshtein距离(也叫做Edit Distance),是指两个 ...
- (DP)51NOD 1183 编辑距离
编辑距离,又称Levenshtein距离(也叫做Edit Distance),是指两个字串之间,由一个转成另一个所需的最少编辑操作次数.许可的编辑操作包括将一个字符替换成另一个字符,插入一个字符,删除 ...
- 51Nod 1183 编辑距离 (字符串相似算法)
编辑距离,又称Levenshtein距离(也叫做Edit Distance),是指两个字串之间,由一个转成另一个所需的最少编辑操作次数.许可的编辑操作包括将一个字符替换成另一个字符,插入一个字符,删除 ...
- 51NOD 1183编辑距离(动态规划)
>>点击进入原题测试<< 思路:这个题放在基础题,分值还是零分,好歹也给人家动态规划一点面子啊!刚开始写的想法是找到其最大公共字串,然后用两个字符串中最长字符串的长度减掉最大公 ...
- 动态规划 51nod 1183
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1183 1183 编辑距离 基准时间限制:1 秒 空间限制:1 ...
- 51 Nod 1183 编辑距离 (动态规划基础)
原题链接:1183 编辑距离 题目分析:这个最少的操作次数,通常被称之为编辑距离."编辑距离"一次本身具有最短的意思在里面.因为题目有"最短"这样的关键词,首先 ...
- 基础dp 记录
51nod 1134 最长递增子序列 #include<iostream> #include<cstdio> #include<cstring> #include& ...
随机推荐
- Linux替换字符串
sed命令批量替换多个文件中的字符串: 命令:sed -i “s/原字符串/新字符串/g” `grep 原字符串 -rl 所在目录` 例如:我要把 xy 替换为 mn,执行命令: sed -i “s/ ...
- sass和css的calc运算
1.sass不识别不同单位之间的计算,而calc则没问题. width: #{1rem - 2px}; /*出错*/ width: calc(1rem - 2px); 通常情况定制css样式,我不需要 ...
- Why String is Immutable or Final in Java
The string is Immutable in Java because String objects are cached in String pool. Since cached Strin ...
- HTML输入框的默认显示内容
在某些情况下我们会需要在输入框里默认显示一些内容,比如在登录的时候不在输入框前面显示用户名和密码,直接在输入框里显示,这时只要在input的标签里添加属性 placeholder="用户名 ...
- 置换检验(Permutation Test)学习[转载]
转自:https://www.cnblogs.com/bnuvincent/p/6813785.html http://www.bioinfo-scrounger.com/archives/564 1 ...
- PAT 1040 Longest Symmetric String[dp][难]
1040 Longest Symmetric String (25)(25 分) Given a string, you are supposed to output the length of th ...
- PAT 1028 List Sorting[排序][一般]
1028 List Sorting (25)(25 分) Excel can sort records according to any column. Now you are supposed to ...
- [LeetCode] 697. Degree of an Array_Easy tag: Hash Table
Given a non-empty array of non-negative integers nums, the degree of this array is defined as the ma ...
- Docker Quickstart Terminal: exit status 255 解决办法
原文地址:https://www.jianshu.com/p/061f1ae69937 初识docker,还有先拿Windows 7 尝试下,官方提供了docker toolbox,下载后一键安装,桌 ...
- Log4net 日志传到 graylog监控
graylog是java的一个日志监控插件.存储用的是mongoDB,效率还是挺高的.不过嘛,文档太少了,安装和配置都很不容易. 官网:http://www.graylog.org/ 在graylog ...