== Псевдокод ==
'''DynamicOptionalStateSequance'''(<tex>\lambda</tex>, D): a'''double''' <tex>\gamma</tex>[1, i] = <tex>\pi</tex>[i]*b[i, d[1]] '''int''' <tex>\psi</tex>[1, i] = [] '''int''' ans[]
'''for''' t = 2 '''to''' T
'''for''' i = 1 '''to''' n
a '''if''' <tex>\gamma</tex>[t, j] += a< <tex>\gamma</tex>[t- 1, i]*a[i, j] * b[j, d[t]] <tex>\gamma</tex>[t, j] = <tex>\gamma</tex>[t - 1, i] * a[ti, j] *= b[j, d[t + 1]] <tex>\psi</tex>[t, j] = i ans[T] = 1 '''for''' i = 1 2 '''to''' n p(D| '''if''' <tex>\lambdagamma</tex>[T, i] > <tex>\gamma</tex>) += a[T, i- 1] ans[T] = i '''for''' t = T - 1 '''downto''' 1 ans[t]= <tex>\psi</tex>[t + 1, ans[t + 1]] '''return''' ans
== Источники ==