def _lcs_length(x, y):
    """
    Computes the length of the longest common subsequence (lcs) between two
    strings. The implementation below uses a DP programming algorithm and runs
    in O(nm) time where n = len(x) and m = len(y).
    Source: http://www.algorithmist.com/index.php/Longest_Common_Subsequence

    >>> _lcs_length('ABCDE', 'CD')
    2
    >>> _lcs_length('the police killed the gunman'.split(), 'gunman police killed'.split())
    2

    :param x: sequence of words
    :param y: sequence of words
    :return: Length of LCS between x and y
    """
    n, m = len(x), len(y)
    len_table = {}

    for i in range(n + 1):
        for j in range(m + 1):
            if i == 0 or j == 0:
                len_table[i, j] = 0
            elif x[i - 1] == y[j - 1]:
                len_table[i, j] = len_table[i - 1, j - 1] + 1
            else:
                len_table[i, j] = max(len_table[i - 1, j], len_table[i, j - 1])

    return len_table[n, m]