correct viterbi algorithm for multiple endstates