ekdoteen123's blog

By ekdoteen123, history, 5 weeks ago, In English,

https://codeforces.com/contest/431/problem/C

The recursive solution works but gives TLE for some inputs.

But when I memoize the solution it doesn't give the same results.

Here is my code: https://pastebin.com/EAX7T9RK

Thanks

Tags #dp
 
 
 
 
  • Vote: I like it  
  • +1
  • Vote: I do not like it  

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

You should initialize the dp array with -1's in order to get correct results.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    even after doing that, I didn't get the desired results.