CSU1060-Nearest Sequence-DP/LCS
来源:互联网 发布:针织短款开衫淘宝网 编辑:程序博客网 时间:2024/06/14 06:05
B: Nearest Sequence
Description
Do you remember the “Nearest Numbers”? Now here comes its brother:”Nearest Sequence”.Given three sequences of char,tell me the length of the longest common subsequence of the three sequences.
Input
There are several test cases.For each test case,the first line gives you the first sequence,the second line gives you the second one and the third line gives you the third one.(the max length of each sequence is 100)
Output
For each test case,print only one integer :the length of the longest common subsequence of the three sequences.
Sample Input
abcdabdcdbcaabcdcabdtsc
Sample Output
21
Hint
三个字符串的LCS,直接套两个的那个来就好了
#include <bits/stdc++.h>#define N 10100#define INF 0x3f3f3f3f#define LL long long#define mem(a,n) memset(a,n,sizeof(a))#define fread freopen("in.txt","r",stdin)#define fwrite freopen("out.txt","w",stdout)using namespace std;int dp[110][110][110];char str0[110],str1[110],str2[110];int main(){// ios::sync_with_stdio(false); str0[0]=str1[0]=str2[0]='#'; while(~scanf("%s",str0+1)){ scanf("%s%s",str1+1,str2+1); int len1=strlen(str0),len2=strlen(str1),len3=strlen(str2); // cout<<len1<<len2<<len3<<endl; int ans=0; for(int i=1;i<len1;++i){ for(int j=1;j<len2;++j){ for(int k=1;k<len3;++k){ int a=max(dp[i-1][j][k],max(dp[i][j-1][k],dp[i][j][k-1])); int b=max(dp[i-1][j-1][k],max(dp[i][j-1][k-1],dp[i-1][j][k-1])); int c=max(a,b); if(str0[i]==str1[j]&&str1[j]==str2[k]){ dp[i][j][k]=max(c,dp[i-1][j-1][k-1]+1); }else{ dp[i][j][k]=c; } if(dp[i][j][k]>ans){ ans=dp[i][j][k]; } } } } printf("%d\n",ans); } return 0;}
阅读全文
0 0
- CSU1060-Nearest Sequence-DP/LCS
- Nearest Sequence(lcs)
- csu 1060 Nearest Sequence
- COJ-1060-Nearest Sequence
- DP:LCS
- LCS-DP
- DP--LCS
- csuoj1060: Nearest Sequence 动态规划
- [DP_BASIC][LCS]Common Sequence
- LCS, longest common sequence
- LCS(Loggest Common Sequence)
- Nearest Sequence+csuoj+最大公共子串
- POJ1080 - DP(LCS变种)
- tyvj-1050 LCS DP
- HDU 1080 DP LCS
- lcs(dp)
- uva10192 - Vacation(dp,lcs)
- hdu 1159 dp - lcs
- CSU1219-建食堂-Floyd/BFS
- DevExpress中GridControl中实现checkbox多行选中
- 交换变量和判断闰年
- leetcode十八周解题报告
- CSU1005-Binary Search Tree analog-模拟
- CSU1060-Nearest Sequence-DP/LCS
- CSU1081-集训队分组-BFS
- 主成分分析(PCA)原理详解
- CSU1092-Barricade-最短路/Dijkstra
- myEclipse 中修改 jsp 文件默认pageEncoding
- CSU1120-病毒-DP/LCS/LIS
- hadoop的mapreduce作业中出现Java heap space,你认为该如何解决?
- 第三学期第六次算法练习题
- CSU1216-异或最大值-0-1Trie树