Union Training II - Dynamic Programming

G: Simple dp