There are two strings A and B with equal length. Both strings are made up of lower case letters. Now you have a powerful string painter. With the help of the painter, you can change a segment of characters of a string to any other character you want. That is, after using the painter, the segment is made up of only one kind of character. Now your task is to change A to B using string painter. What’s the minimum number of operations?

InputInput contains multiple cases. Each case consists of two lines: 
The first line contains string A. 
The second line contains string B. 
The length of both strings will not be greater than 100. 
OutputA single line contains one integer representing the answer.Sample Input

zzzzzfzzzzz
abcdefedcba
abababababab
cdcdcdcdcdcd

Sample Output

6
7 区间dp,但是具体实现,没实现,参考了一下题解:链接:https://blog.csdn.net/martinue/article/details/45953229
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath> const int maxn=1e5+;
typedef long long ll;
using namespace std; int a[],dp[][];
char s1[],s2[];
int solve(int i,int j)
{
if(dp[i][j]!=-)
return dp[i][j];
if(i>j)
return dp[i][j]=;
if(i==j)
return dp[i][j]=;
dp[i][j]=solve(i+,j)+;
for(int k=i+;k<=j;k++)
if(s2[k]==s2[i])
dp[i][j]=min(solve(i+,k)+solve(k+,j),dp[i][j]);
return dp[i][j];
} int main ()
{
while(cin>>s1>>s2)
{
memset(dp,-,sizeof(dp));memset(a,,sizeof(a)); int len =strlen(s1);
for(int i=;i<len;i++)
{
for(int j=i;j<len;j++)
int t=solve(i,j);
}
for(int i=;i<len;i++)
{
a[i]=dp[][i];
if(s1[i]==s2[i])
{
if(i==)
a[i]=;
else
a[i]=a[i-];
}
else
{
for(int j=;j<i;j++)
a[i]=min(a[i],a[j]+dp[j+][i]);
}
}
printf("%d\n",a[len-]);
}
return ;
}

最新文章

  1. IIS 发布添加网站错误:HTTP 错误 500.21 - Internal Server Error 解决方案
  2. python核心编程第六章练习6-15
  3. OpenWrt资料汇总
  4. SVM+HOG特征训练分类器
  5. Java基础(41):Java中集合中需要注意的几个要点(关于Collection与Map)
  6. 代码方式删除SVN
  7. php定时执行任务的几个方法
  8. H面试程序(10): 字符串包含问题
  9. SQL Server 对表的 12 种一般性操作
  10. combobox自己主动提示组件加入无选中项清空功能
  11. 内存管理之slab分配器
  12. 新手使用mac上的textedit写HTML时遇到的问题及解决办法
  13. mysql数据库--explain(查询表是否走索引)各个字段含义
  14. pointer-events属性屏蔽鼠标事件(点击穿透上层元素)
  15. 【Pyton】【小甲鱼】魔法方法
  16. 高效开发 Android App 的 10 个建议
  17. http请求头中的Content-Type属性在angular 和 node中的用法
  18. linux基础命令学习 (十)Vi
  19. [转]PHP运行出现Notice : Use of undefined constant 的完美解决方案
  20. QMesageBox的使用

热门文章

  1. CSS基础知识(下)
  2. IOS - ACL (访问控制列表)
  3. akka-typed(9) - 业务分片、整合,谈谈lagom, 需要吗?
  4. 2020-07-29:从 innodb 的索引结构分析,为什么索引的 key 长度不能太长?
  5. Web优化躬行记(4)——用户体验和工具
  6. 01 Arduino-点亮一盏LED灯
  7. 初识ABP vNext(4):vue用户登录&amp;菜单权限
  8. pytest封神之路第一步 tep介绍
  9. Python开发的入门教程(一)-数据类型、变量
  10. 操作系统-I/O(6)I/O与系统调用