Google Interview Question

classic dynamic programming problem with a twist