zoukankan      html  css  js  c++  java
  • Longest common subsequence problem

    http://en.wikipedia.org/wiki/Longest_common_subsequence_problem

    LCS function defined

    Let two sequences be defined as follows: X = (x1, x2...xm) and Y = (y1, y2...yn). The prefixes of X are X1, 2,...m; the prefixes of Y are Y1, 2,...n. Let LCS(Xi, Yj) represent the set of longest common subsequence of prefixes Xi and Yj. This set of sequences is given by the following.

    LCS\left(X_{i},Y_{j}\right) = \begin{cases}   \empty & \mbox{ if }\ i = 0 \mbox{ or }  j = 0 \\   \textrm{ ( } LCS\left(X_{i-1},Y_{j-1}\right), x_i) & \mbox{ if } x_i = y_j \\   \mbox{longest}\left(LCS\left(X_{i},Y_{j-1}\right),LCS\left(X_{i-1},Y_{j}\right)\right) & \mbox{ if } x_i \ne y_j \\ \end{cases}

    To find the longest subsequences common to Xi and Yj, compare the elements xi and yi. If they are equal, then the sequence LCS(Xi-1, Yj-1) is extended by that element, xi. If they are not equal, then the longer of the two sequences, LCS(Xi, Yj-1), and LCS(Xi-1, Yj), is retained. (If they are both the same length, but not identical, then both are retained.) Notice that the subscripts are reduced by 1 in these formulas. That can result in a subscript of 0. Since the sequence elements are defined to start at 1, it was necessary to add the requirement that the LCS is empty when a subscript is zero.

    http://www.csie.ntnu.edu.tw/~u91029/LongestCommonSubsequence.html 

  • 相关阅读:
    ECMAScript与JavaScript
    AngularJS多模块开发与路由
    ionic调用摄像头
    ionic 打包
    ionic简介
    git---小乌龟提交
    git---控制面板提交
    获取百度网盘真实下载地址
    js高级---本地对象、内置对象、宿主对象
    js高级---js架构
  • 原文地址:https://www.cnblogs.com/cutepig/p/1741203.html
Copyright © 2011-2022 走看看