Combinatorics meets dynamic programming: when counting becomes computation