light oj 1159 - Batman LCS
来源:互联网 发布:暴风魔镜软件下载 编辑:程序博客网 时间:2024/04/26 22:32
学过简单动态规划的人应该对最长公共子序列的问题很熟悉了,这道题只不过多加了一条字符串变成三条了,还记得,只要把状态变成三维的即可。
//http://lightoj.com/volume_showproblem.php?problem=1159//2013-08-15-09.50#include <iostream>#include <stdio.h>#include <algorithm>#include <string.h>using namespace std;char str1[55];char str2[55];char str3[55];int dp[55][55][55];int maxval(int a, int b, int c){ a = max(a, b); a = max(a, c); return a;}int main(){ int t, kase = 0; scanf("%d", &t); while (t--) { int ans = 0; scanf("%s %s %s", &str1[1], &str2[1], &str3[1]); int l1 = strlen(&str1[1]); int l2 = strlen(&str2[1]); int l3 = strlen(&str3[1]); memset(dp, 0, sizeof(dp)); for (int i = 1; i <= l1; i++) { for (int j = 1; j <= l2; j++) { for (int k = 1; k <= l3; k++) { if (str1[i] == str2[j] && str2[j] == str3[k]) dp[i][j][k] = dp[i-1][j-1][k-1] + 1; else { dp[i][j][k] = maxval(dp[i-1][j][k], dp[i][j-1][k], dp[i][j][k-1]); } } } } printf("Case %d: %d\n", ++kase, dp[l1][l2][l3]); } return 0;}
- light oj 1159 - Batman LCS
- Light oj 1159 - Batman(三维 LCS)
- Light OJ 1159 Batman (简单DP)
- lightoj 1159 - Batman LCS
- LCS dp Batman lightoj 1159
- light oj An Easy LCS
- light oj 1013 LCS 应用
- light oj 1110 LCS 记录路径
- Light OJ 1157 LCS Revisited (DP)
- Light oj 1110 LCS带打印路径
- light oj 1033 - Generating Palindromes (LCS)
- light oj 1033 - Generating Palindromes 【LCS】
- Light oj 1110 - An Easy LCS(LCS)
- Light OJ 1013 - Love Calculator(LCS+ 计方案数)
- Light OJ 1110 An Easy LCS (DP+路径记录)
- Light OJ:1033 Generating Palindromes(LCS+回文字符串)
- Light OJ 1110 - An Easy LCS (LCS+字典序最小路径记录)
- Light oj 1157 - LCS Revisited(lcs 个数 记忆化搜索)
- Git Stash用法
- hdu4515小Q系列故事——世界上最遥远的距离
- C# 对自定类型排序
- QT中委托(QItemDelegate/QStyledItemDelegate)的使用,以及自定义Delegate
- easyui datagrid pagination
- light oj 1159 - Batman LCS
- 一次迭代式开发的研究11:Where you are
- GSL矩阵操作1
- Linux常用命令(二)
- websphere中的会话超时设置 和 web应用中web.xml中session-timeout关系
- Android第二个绕过签名认证漏洞原理
- HashMap和Hashtable及HashSet的区别<转>
- QT 利用ListWidget 和 StackedLayout 配合实现 分页 选项
- hdu 1060 数学