Light oj 1159 - Batman(三维 LCS)
来源:互联网 发布:java 写html文件 编辑:程序博客网 时间:2024/04/20 19:11
Batman is in deep trouble. You know that superheroes are there to help you when you are in trouble. But in Gotham city there is no trouble. So, 'no trouble' is actually the trouble for our Batman.
So, Batman is trying to solve ACM problems because he wants to be a good programmer like you :). But alas! He is not that smart. But still he is trying. He found 3 strings of characters. Now he wants to find the maximum string which is contained in all the three strings as a sub sequence. He wants to find the maximum length, not the sequence.
Now, Batman claims that he is a better programmer than you. So, you are solving the same problem. Can you solve faster? You are guaranteed that Batman will need 3 hours to solve the problem. So, you have to be faster than him.
Input
Input starts with an integer T (≤ 200), denoting the number of test cases.
Each case will contain a blank line and three strings in three lines. None of the string lengths will be greater than 50 and less than 1. And the string will contain alphanumeric characters only.
Output
For each case, print one line containing the case number and the length of the largest subsequence.
Sample Input
Output for Sample Input
3
abcdef
cdef
dcdef
aaaa
bbbb
ccca
aaaa
aaaa
aaa
Case 1: 4
Case 2: 0
Case 3: 3
#pragma comment(linker, "/STACK:1024000000,1024000000")#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<stack>#include<vector>#include<set>#include<map>#define L(x) (x<<1)#define R(x) (x<<1|1)#define MID(x,y) ((x+y)>>1)#define bug printf("hihi\n")#define eps 1e-8typedef long long ll;using namespace std;#define INF 0x3f3f3f3f#define N 60char a[N],b[N],c[N];int dp[N][N][N];int main(){ int i,j,t,k,ca=0; scanf("%d",&t); while(t--) { scanf("%s%s%s",a+1,b+1,c+1); int lena=strlen(a+1); int lenb=strlen(b+1); int lenc=strlen(c+1); memset(dp,0,sizeof(dp)); for(i=1;i<=lena;i++) for(j=1;j<=lenb;j++) for(k=1;k<=lenc;k++) if(a[i]==b[j]&&b[j]==c[k]) dp[i][j][k]=dp[i-1][j-1][k-1]+1; else dp[i][j][k]=max(max(dp[i-1][j][k],dp[i][j-1][k]),dp[i][j][k-1]); printf("Case %d: %d\n",++ca,dp[lena][lenb][lenc]); } 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 个数 记忆化搜索)
- javascript闪烁图片
- 关于mysql中文插入 问号??问题的解决方法!
- HDU - 1176 免费馅饼(DP)
- ViewPager防止Fragment销毁以及取消Fragment的预加载
- 大视野2038 小z的袜子 莫队算法
- Light oj 1159 - Batman(三维 LCS)
- sed study
- Java学习之多态
- matplotlib绘图
- 笔试面试题总结(二)---软件开发
- hibernate一对一主键关联映射
- 排序算法六:选择排序之直接选择排序
- ArcGIS教程:坡度
- HDU - 1260 Tickets(DP)