Блог пользователя melikeairplanes

Автор melikeairplanes, история, 16 месяцев назад, По-английски

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 - Кевин и головоломка, 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 - Скука, 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.

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится

»
16 месяцев назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

refer vivek gupta's dp workshops acraider

»
16 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

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.

»
16 месяцев назад, скрыть # |
 
Проголосовать: нравится +15 Проголосовать: не нравится

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