poj 1458 LCS
2015-08-07 16:31
316 查看
#include <stdio.h> #include <string.h> #include <algorithm> #pragma warning (disable :4996) using namespace std; const int Max = 1000; int dp[Max][Max]; char str1[Max], str2[Max]; int LCS(int lenstr1, int lenstr2) { memset(dp, 0, sizeof(dp)); for (int i = 1; i <= lenstr1; i++) { for (int j = 1; j <= lenstr2; j++) { if (str1[i - 1] == str2[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1; else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); } } return dp[lenstr1][lenstr2]; } int main() { while (~scanf("%s %s", str1, str2)) { int m = strlen(str1); int n = strlen(str2); printf("%d\n", LCS(m, n)); } return 0; }
相关文章推荐
- Linux Notes
- 循环-11. 水仙花数(20)
- 做了三年开发 到现在才完美解决了弹键盘的问题
- Fiddler调试线上JS代码
- 正则表达式
- git
- JAVASCRIPT——正则表达式
- win10如何开启自带的防火墙?win10防火墙开启方法
- ANDROID系统广播总结
- @符号截取(最简单的字符串截取)
- 自定义ActionBar
- ifconfig
- android学习View Animation
- iOS正则表达式验证等各种
- Android out of memory(二)
- MySQL锁用法介绍
- 【asp.net】GridView中模板的使用
- 基础控件(一)
- VS2013安装SVN插件
- java properties