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

Автор Noneqw, история, 4 года назад, По-английски

Hello codeforces,

i have take many recursion tutorials , but i still couldn't solve a lot of recursive style problems and if i see their solutions i can't trace it executing , so also i can't learn DP well :(

please give me advises to solve this trouble and best tutorials and best platforms to training on recursion problems

thanks in advance...

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

»
4 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Maybe some more exercise could help =)))) you could search in a2oj categories for some DP and if you're in trouble just looking for some solution on Quora =)))) many solutions is DP with memozation and that not mean you cant learn DP well

»
4 года назад, # |
  Проголосовать: нравится +7 Проголосовать: не нравится

recursion trouble

»
4 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

There's no complate or style for recursion.I think dp is easier to understand than recursion.dp is more intuitive

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +2 Проголосовать: не нравится

    How can he make transitions if he cannot understand recursions? Thinking about states of a DP is easy compared to making a transition. Usually, transitions are easy. But a few times they are hard.

»
4 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

These two helped me a lot during my initial days. You can give it a try. I hope you will get some help.

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I understand. Recursion is difficult to think. Here's how I would approach them: 1. Understand the problem and jot down all the properties you notice. 2. See how you can get the answer for the current state by knowing the answers of subproblems. 3. Think of the answer for the basic state like n = 0 or something.

Let me help you. Please go through 1369D - TediousLee and think for a solution (not telling you Fibonacci as you would have gone through it a thousand times).

What I notice here is the fact that RDB(n) is made of 2 RDB(n — 2) trees and one RDB(n — 1) tree (see and draw more examples to understand).

So, answer is RDB(n) = 2 * RDB(n — 2) + RDB(n — 1) + (i % 3 == 0). Eg: n = 6 So it consists of RDB(4) and RDB(5). Notice that in both RDB(4) and RDB(5), nodes 4 and 5 are not part of the claws respectively. Therefore, (6 4 5 4) claw is added. That explains the equation.

Point being the main recursion formula is derived by some properties in the problem. With time and practice, it will become clearer. DP is memoizing the values you calculate in recursion, so we need not calculate them again.

Not a great explanation but I hope you get the point.

»
4 года назад, # |
  Проголосовать: нравится +2 Проголосовать: не нравится

I like to think of recursion as a Tree it really does help me with visualization