lcs连续
来源:互联网 发布:教育软件代理 编辑:程序博客网 时间:2024/04/30 09:05
一个序列 S ,如果分别是两个或多个已知序列的子序列,且是所有符合此条件序列中最长的,则 S 称为已知序列的最长公共子序列。
转移方程:
dp[i,j] = 0 i=0 || j=0
dp[i,j] = dp[i-1][j-1]+1 i>0,j>0, a[i] = b[j]
dp[i,j] = max(dp[i-1][j],dp[i][j-1]) i>0,j>0, a[i] != b[j]
- #include "stdio.h"
- #define M 8
- #define N 6
- void printLSC(int i, int j,char *a, int status[][N]){
- if(i == 0 || j== 0)
- return;
- if(status[i][j] == 0){
- printLSC(i-1,j-1,a,status);
- printf("%c",a[i]);
- }else{
- if(status[i][j] == 1)
- printLSC(i-1,j,a,status);
- else
- printLSC(i,j-1,a,status);
- }
- }
- main(){
- int i,j;
- char a[] = {' ','A','B','C','B','D','A','B'};
- char b[] = {' ','B','D','C','B','A'};
- int status[M][N]; //保存状态
- int dp[M][N];
- for(i = 0; i < M; i++)
- for(j = 0; j < N; j++){
- dp[i][j] = 0;
- status[i][j] = 0;
- }
- for(i = 1; i < M; i++)
- for(j = 1; j < N; j++){
- if(a[i] == b[j]){
- dp[i][j] = dp[i-1][j-1] + 1;
- status[i][j] = 0;
- }
- else if(dp[i][j-1] >= dp[i-1][j]){
- dp[i][j] = dp[i][j-1];
- status[i][j] = 2;
- }
- else{
- dp[i][j] = dp[i-1][j];
- status[i][j] = 1;
- }
- }
- printf("最大长度:%d",dp[M-1][N-1]);
- printf("\n");
- printLSC(M-1,N-1,a,status);
- printf("\n");
- }
0 0
- lcs连续
- LCS(子串必须连续)
- 【数据结构与算法】LCS(不连续)
- 【数据结构与算法】LCS(连续)
- HDU1231 最大连续子序列(LCS)
- LCS(最长连续子序列+最长连续字串)
- 最大公共连续子串(LCS问题)
- LCS问题变型,要求子序列必须连续
- CF 427D Match & Catch 求最短唯一连续LCS
- [DP]LIS+LCS+最大连续子段和
- LCS 最长公共子序列问题(非连续的)
- 最长公共子串(LCS)(连续与非连续)
- LCS
- LCS
- lcs
- LCS
- LCS
- LCS
- 微信调试器
- QT (Application Example)
- 17082 两个有序数序列中找第k小(递归)
- leetcode:Pascal's Triangle
- CSDN博客使用心得
- lcs连续
- bank笔题目记录1
- Centos7(Linux)版OpenVPN安装、配置教程
- 用不用Delegate,这是一个问题
- uva 348(dp)
- 怎样把数组作为参数传递给函数
- 幂等性 个人理解及应用
- 【设计模式】策略模式的理解
- 第6、7讲阅读程序结果检验6