Dynamic programming techniques based on Markov assumptions, such as Viterbi decoding, cannot handle those 'non-local' constraints as discussed above.
it is possible to constrain Viterbi decoding by 'local' constraints, e.g.