melikeairplanes's blog

By melikeairplanes, history, 38 hours ago, In English

I learnt dynamic programming from here striver and this guy solves all problems using a same pattern, where dp represents the final answer of the sub-problem(ex — in fibonacci, dp[i] represents fibo number at index i), I did around 50 questions(easy, med and hard) from the same source. Now, when I started dp questions on codeforces, I have seen something new, were dp do not represent the answer of subproblem, rather than there is a way of finding answer from dp, like this 2061C - Kevin and Puzzle, int this, my approach was to define dp[i][lr] = number of possible ways till index i (**without** any condition on if the person in index i is liar or honest) if there are lr number of liars, which corresponds to what I learnt from youtube, but the solution says dp[i] = nunmber of possible ways considering ith person is honest and at last add dp[n]+dp[n-1]. Another problem like this is 455A - Boredom, in which the dp[i] don't represents answer till index i(my first approach), rather dp[i] represents the longest length if the max element is i, and many other question Shayan's Topic streams. He is also doing the same, many times, dp do not directly represents the answer, but answer can be calculated via dp. How and where to learn this? How to decide the states? I able to questions almost every time in contests where dp represents the direct answer of the subproblem, but whenever there is a problem where dp do not represent the answer, my brain stops, and when i see the editorial, I am always disappointed, is there some trick or else i don't know or else. How can i learn this? Help me :) please.

  • Vote: I like it
  • +3
  • Vote: I do not like it

»
37 hours ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

refer vivek gupta's dp workshops acraider

  • »
    »
    34 hours ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    ok

  • »
    »
    34 hours ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    are they good? i was thinking of referring them, but have got mixed reviews about them.

»
33 hours ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

This comes with experience on the tougher problems, Also there are many binary search problems where the good function is created using some dynamic programming. They are just some variants where you learn them from experience. I would suggest you to refer USACO guide and Colin Galen Youtube channel.

»
33 hours ago, hide # |
 
Vote: I like it +15 Vote: I do not like it

i hate how dp is taught to us as if it was something magical, to learn dp all you need to know is that u could make use of recurrences there is no pattern if you happen to calculate something using a recurrence formula then its probably because its either easy or faster than calculating the final value immediately

  • »
    »
    30 hours ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I so much agree. They just teach how to write a recurrence solution and store them in something cool called states. Most of them fail to convey the intuitive part of DP which allows you to solve non conventional harder DP problems.

  • »
    »
    24 hours ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    how was it taught to you? it might also work for me.

    • »
      »
      »
      19 hours ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      it was taught to me the same perhabs "wrong" way that it was taught to anybody, things got somewhat right after about 200 ish dp problems