最短公共子序列_最短公共超序列

本文介绍了如何找到两个字符串之间的最短公共超序列,并通过动态规划算法进行求解。文章详细阐述了算法思路,包括如何计算最长公共子序列,以及如何结合非公共元素得到最短超序列的长度。此外,还提供了递归算法和DP转换的实现示例。
摘要由CSDN通过智能技术生成

最短公共子序列

Problem statement:

问题陈述:

Given two strings, you have to find the shortest common super sequence between them and print the length of the super sequence.

给定两个字符串,您必须找到它们之间最短的公共超级序列,并打印超级序列的长度。

    Input:
    T Test case
    T no of input string will be given to you.

    E.g.
    3
    
    abcd abxy
    sghk rfgh
    svd vjhfd
    
    Constrain 
    1≤ length (string1) ≤100
    1≤ length (string2) ≤100
    
    Output:
    Print the length of the shortest super sequence formed from these two strings.

Example

    T=3

    Input:
    abcd abxy
    
    Output:
    6 (abcdxy)
    
    Input:
    sghk rfgh
    
    Output:
    6 (srfghk)
    
    Input:
    svd vjhfd
    
    Output:
    6 (svjhfd)

Explanation with example:

举例说明:

Let there are two strings str1 and str2.

假设有两个字符串str1和str2 。

    str1 = "abcd" 
    str2 = "abxy"

To find out the length of the super sequence from these two string is a bit difficult. To solve this problem we have to follow these steps:

从这两个字符串中找出超级序列的长度有些困难。 要解决此问题,我们必须遵循以下步骤:

  1. We hav

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值