function p = viter(A,B)

Q=size(A,1);
T=size(B,2);

Fi = zeros(Q,T);
Fi(2:Q-1,1) = log_(A(1,2:Q-1))' .* log_(B(2:Q-1,1));

for t = 2 : T
    for j = 2 : (Q-1)
        Fi(j,t) = max ( Fi(2:Q-1,t) + log_(A(2:Q-1,j))) + log_(B(j,t));
    end
end

p = ( max ( Fi(2:Q-1,T) + log_(A(2:Q-1,Q))) );

end