Added optimal solution of problem B using DP