Google Interview Question

A DP problem about combinatorics