Viterbi Algorithm for HMM problem, details can be seen here