C++ implementation of viterbi algorithm