finish viterbi algorithm.