greedy algo, same to the assignment of 5454
classic recursion and dp