Для начала вы можете, по крайней мере, уменьшить проблему, рассчитав установить симметричную разность , чтобы исключить любые триплеты, которые не встречаются в обеих последовательностях.
Для самой длинной подпоследовательностиАлгоритм использует динамическое программирование подход.Для каждого триплета найдите самую короткую подстроку длины два, которая встречается в обоих.Цикл по этим парам, пытаясь расширить их путем объединения пар.Продолжайте расширяться, пока у вас не будет всех самых длинных расширений для каждого триплета.Выберите самый длинный из них:
ABQACBBA
ZBABBA
Eliminate symmetric difference
ABABBA and BABBA
Start with the first A in ABABBA.
It is followed by B, giving the elements [0,1]
Check to see if AB is in BABBA, and record a match at [1,2]
So, the first pair is ((0,1), (1,2))
Next, try the first B in ABABBA.
It is followed by an A giving the elements [1,2]
Check to see if BA is in BABBA and record a match at [0,1]
Continue with the rest of the letters in ABABBA.
Then, try extensions.
The first pair AB at [0,1] and [1,2] can be extended from BA
to ABA [0,1,3] and [1,2,4]. Note, the latter group is all the
way to the right so it cannot be extended farther. ABA cannot
be extended.
Continue until all sequences have extended are far as possible.
Keep only the best of those.