最长公共子序列
2016-08-26 11:10
323 查看
/************************************************* *@time 2016/08/25 9:48 *@place ctrip.15#.9f **************************************************/ #include<cstdio> #include<cstring> #define MAX_LENGTH 100 int main() { char str1[]="123456789"; char str2[]="123"; int dp[10][4]; for(int i=0;i<=9;i++) { for(int j=0;j<=3;j++) { dp[i][j]=0; } } for(int i=1;i<=9;i++) { for(int j=1;j<=3;j++) { if(str1[i-1]==str2[j-1]) { dp[i][j]=dp[i-1][j-1]+1; } else if(dp[i-1][j]>dp[i][j-1]) { dp[i][j]=dp[i-1][j]; } else { dp[i][j]=dp[i][j-1]; } } } printf("%s %s\n",str1,str2); for(int i=9,j=3;i>0&&j>0;) { if(str1[i-1]==str2[j-1]) { printf("%c ",str1[i-1]); i--; j--; } else if(dp[i-1][j]>dp[i][j-1]) { i--; } else { j--; } } }
相关文章推荐
- http报文中字段解析
- 【bzoj1081】[SCOI2005]超级格雷码
- 如何用Maven创建web项目(具体步骤)
- 【分享】bootstrap学习笔记
- 文本比较工具 Beyond Compare
- 夜诊JS跳转
- 苏一光700系列后处理软件 官方版
- whereis, which, locate的区别
- 基于STM32的BMP图片解码
- SLAM让你如何去理解这个世界
- SQL Server 批量插入数据的两种方法
- ThinkPHP 查询语言
- MBProgressHUD的简单使用
- letsencrypt 快速入手
- 用递归找出数组中最小的元素
- 图片无限轮播
- AMS分析--基于深入理解android(3)
- Android 自适应的一种布局,weight
- JVM架构(001)_java内存模型是什么样的
- Delphi:与VCL同步(Synchronize()、用消息来同步)