MINIMUM-PATH-SUM problem solved with recurrence and counter matrix