# How to use Viterbi algorithm for multiple chain HMM?

I need to build a HMM with two chains: the structure is as the figure below. How can I use the Viterbi algorithm for this model?

Multiple layered HMM is equivalent to a single layered HMM with larger state space. For example, if you have $M$ layers and $K$ states in each layer, you can construct a single layer HMM with state space size of $K^M$ and then use the regular Viterbi Algorithm. To construct the single layered HMM with exponential state space, you have to go through all possible states in each layer.