csu 1060 Nearest Sequence
来源:互联网 发布:淘宝店可以用手机开么 编辑:程序博客网 时间:2024/06/08 09:55
题目描述
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.
输入
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)
输出
For each test case,print only one integer :the length of the longest common subsequence of the three sequences.
样例输入
abcdabdcdbcaabcdcabdtsc
样例输出
21
提示
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.
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)
For each test case,print only one integer :the length of the longest common subsequence of the three sequences.
思路:简单的动态规划,原始LCS,把以前的二维代码加了一维,AC。
#include <cstring> #include <cstdlib> #include <cstdio> #define Max( a, b ) (a) > (b) ? (a) : (b)using namespace std;char s1[105], s2[105],s3[105];int dp[105][105][105];int main() { int len1, len2 , len3; while( scanf( "%s %s %s", s1, s2 ,s3 ) != EOF ) { memset( dp, 0, sizeof(dp) ); len1 = strlen( s1 ), len2 = strlen( s2 ); len3 = strlen( s3 ); for( int i = 1; i <= len1; ++i ) { for( int j = 1; j <= len2; ++j ) { for (int k= 1; k <= len3; ++k) { if( s1[i-1] == s2[j-1] && s1[i-1] == s3[k-1] ) { dp[i][j][k] = dp[i-1][j-1][k-1] + 1; } else { dp[i][j][k] = Max ( dp[i-1][j][k], dp[i][j-1][k] ); dp[i][j][k] =Max (dp[i][j][k],dp[i][j][k-1]); } } } } printf( "%d\n", dp[len1][len2][len3] ); } return 0; }
0 0
- csu 1060 Nearest Sequence
- COJ-1060-Nearest Sequence
- Nearest Sequence(lcs)
- CSU 1555 Inversion Sequence
- CSU 1515 - Sequence (莫队)
- CSU 1515: Sequence
- csuoj1060: Nearest Sequence 动态规划
- CSU1060-Nearest Sequence-DP/LCS
- csu 1555: Inversion Sequence(vector)
- CSU 1203 Super-increasing sequence
- CSU - 1203 Super-increasing sequence
- Nearest Sequence+csuoj+最大公共子串
- [CSU 2005 Nearest Maintenance Point Submit Page] Dijkstra
- CSU 1203 Super-increasing sequence (模拟)
- CSU 1271: Brackets Sequence(数学啊 )
- CSU 1515 Sequence(莫队算法)
- CSU 1515: Sequence(莫队算法)
- CSU 1515Sequence 莫队算法
- 社説 20150530 安保法案審議 専守防衛の本質は変わらない
- TCP/IP、Http、Socket的区别
- 每日一题31:图的遍历
- shell-mysql
- 连续时间马尔科夫过程
- csu 1060 Nearest Sequence
- Page、Request、Session、Application
- 安卓的进程与线程及其相关代码实现
- linux(centos7)搭建nginx服务器
- Codeforces Round #305 (Div. 2) C. Mike and Frog
- arduino最版!!!!1.6.4官方正版
- Install JDK on the Cent Os 6.2
- ubuntu 更改文件所属用户
- 3.2-1