adding dp algorithm