POJ 1458 Common Subsequence (DP 动态规划)
来源:互联网 发布:轮毂数据怎么看 编辑:程序博客网 时间:2024/05/21 22:27
#include <stdio.h>#include <string.h>#define MAX_LEN 1000#define MAX(x, y) ( (x) > (y) ? (x) : (y) )char str1[MAX_LEN];char str2[MAX_LEN];//lenOfLCS[i][j]表示字符串str1的i个前缀和字符串str2的j个前缀的LCS的长度int lenOfLCS[MAX_LEN][MAX_LEN];//length of longest common subsequenceint main(){while (scanf("%s%s", &str1[1], &str2[1]) != EOF){int m = strlen(&str1[1]);int n = strlen(&str2[1]);int i, j;for (i = 0; i <= m; i++)for (j = 0; j <= n; j++)lenOfLCS[i][j] = 0;for (i = 1; i <= m; i++)for (j = 1; j <= n; j++)if (str1[i] == str2[j])lenOfLCS[i][j] = lenOfLCS[i - 1][j - 1] + 1;else lenOfLCS[i][j] = MAX(lenOfLCS[i - 1][j], lenOfLCS[i][j - 1]);printf("%d\n", lenOfLCS[m][n]);}return 0;}
0 0
- poj 动态规划DP - 1458 Common Subsequence
- POJ 1458 Common Subsequence (DP 动态规划)
- POJ 1458-Common Subsequence (动态规划)
- poj 1458 小白算法练习 Common Subsequence 动态规划
- poj 1458 Common Subsequence 【DP】
- DP-POJ-1458-Common Subsequence
- poj 1458Common Subsequence (dp)
- POJ 1458 Common Subsequence DP
- 动态规划 Common Subsequence
- 动态规划之前缀动态规划:poj 1458 Common Subsequence(最长公共子序列)
- 动态规划(DP)---LCS(the Longest Common Subsequence)
- HDU 1159.Common Subsequence【动态规划DP】【3月8】
- POJ 1458 || HDOJ 1159 Common Subsequence (DP)
- POJ 1458 Common Subsequence DP(LCS)
- POJ 1458 Common Subsequence 经典DP
- POJ 1458 Common Subsequence (DP,LCS)
- 【DP|LCS】POJ-1458 Common Subsequence
- POJ 1458 Common Subsequence dp基础
- w3语言学习教程
- JLink RTT Client代替printf(IAR测试OK)
- #ifndef 头文件重复定义
- Linux串口编程详解
- 关于 ZigBee WiFi Bluetooth 的分析
- POJ 1458 Common Subsequence (DP 动态规划)
- unity3d引擎的资源管理机制
- 关于ZigBee的学习记录
- Linux下C++的man安装及使用方法
- Android 5.0 API新增和改进
- C++中vector使用详细说明
- 苹果支持电话
- C++接口实现总结 http://qimo601.iteye.com/blog/1393427
- C++引用与指针的比较