adamWarlock's blog

By adamWarlock, history, 5 years ago, In English

Problem link is here.

Can someone please provide any hint on how to solve this question? I am trying to learn dp, If someone could spare some time it would be great.

  • Vote: I like it
  • -7
  • Vote: I do not like it

»
5 years ago, # |
  Vote: I like it +1 Vote: I do not like it

We can solve it without dp too in O(N^2) using contribution to total sum trick, consider an arbitary subarray [l,r] assume this is a single segment and there are separators between Ar & Ar+1 , Al-1, Al , so now we have k-3 separators left to place in left segment and right segment and multiply this product by avaliable gaps in both left and right combined let this number be g , ans+=product*gCk-3 do this for all subarrays and u get the answer.