}
return head;
}
private static ViterbiNode setMincostNode(ViterbiNode vn, ViterbiNodeList prevs) {
final ViterbiNode f = vn.prev = prevs.get(0);
int minCost = f.cost + Matrix.linkCost(f.posId, vn.posId);
for(int i=1; i < prevs.size(); i++) {
final ViterbiNode p = prevs.get(i);
final int cost = p.cost + Matrix.linkCost(p.posId, vn.posId);
if(cost < minCost) {
minCost = cost;
vn.prev = p;