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

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

I need a plan to improve myself in DP as i think this topic is hard to me and don't know the main idea of it and when we use DP in general.

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

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

i think the most important part in dp problems is first to recognize if the problem is dp, and how to find transitions and also sometimes u may need some observations to optimize the complexity.

  • »
    »
    9 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    How can i learn that?

    • »
      »
      »
      9 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      ig it comes with practice and solving problems ,for me the most straighforward to practice dp,is to just tag dp in the problemset,and pick some considerably recent probelms and try to solve them.

    • »
      »
      »
      9 месяцев назад, скрыть # ^ |
      Rev. 2  
      Проголосовать: нравится 0 Проголосовать: не нравится

      As for me, I keep in mind that DP is mainly used in problems related to counting or on problems where we need to do an optimization to find a minimum or maximum number of operations/value. This helps me in recognizing a DP problem. Apart from that when its hard to find a good logic just try thinking of the problem in a DP or recursive way.

      • »
        »
        »
        »
        7 месяцев назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится

        as you said "DP is mainly used in problems related to counting or on problems where we need to do an optimization to find a minimum or maximum number of operations/value.", I just wanted to add that, dp is also used in problems where we need to make decisions in every step, the difference between dp and greedy is that in greedy we mainly choose one (!) approach and apply it in every stage, whereas in dp, we should consider all the possible situation on that specific stage and then make a decision for that particular situation, where finding the specific formula or approach to make that decision is the main idea in problems.

        I just wondered; if you've practiced alot before and then posted this blog, maybe the problem could be from the "implementation knowledge" you have, cause the implementation in dp is somehow deep and maybe confusing.

        what worked for me was that I just tried to close my eyes and trace 2 or 3 nested for loops, while updating some matrix, both forward and backward methods, then when I've got familiar with this kinda of situations, recognizing dp problems wasn't that hard and the fun part was that how can I apply the idea in those nested loops while using and updating my matrix :)

        Tried to do my best as simple as possible <3

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

If you want to become master in DP then prefer this series. Contains 12 different DP Patterns (1D To Graph DP). 160+ DP problems in which 115+ are from LeetCode. Which means by the end of this series you'll end up solving 115+ DP problems of LeetCode. Its for free on LeetCode: https://leetcode.com/discuss/interview-question/5659029/ultimate-dynamic-programming-series-on-leetcode

»
9 месяцев назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится
  • »
    »
    6 дней назад, скрыть # ^ |
     
    Проголосовать: нравится +3 Проголосовать: не нравится

    Thx bro.

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

CSES dp section, Atcoder educational dp contest

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

Try Vivek Gupta's DP workshop on YT and then try solving CSES problems (you can skip the last 2-3 for now). And try to solve more and more DP problems from CodeForces

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

There is a specific AtCoder contest for exactly that theme

And here is the editorial

Hope that it will help you a lot!

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

Learn from Aditya Verma DP from Youtube

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

Learn from Takeuforward on Youtube. I think that's enough to build strong foundation in DP.

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

This magic stuff had me doubting if a gm was really asking this.

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

I think DP is something that comes with experience. You don’t have to learn everything at once, but at the beginning you should learn some basic stuff and understand the right way to think.( by solving more)

If possible try to learn iterative DP first. You can also follow this problem set,it’s more than enough to master DP: list

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

When I see a problem I always try to find greedy approach first. I give 5min to think for any greedy approach and I think if I am progressing with any idea I continue else move to DP. Now in Dp you have basic Dp which are 1D,2D,3D,partition,LCS,LIS etc.. Then I learned bitmask and digitdp. Honestly Bitmask is very helpful in cf while digitdp is good for recent leetcode contest. Then extend it with exclusion-inclusion and problems that are mix of dp + e/i (here bitmask dp comes too alot). Then I think most important thing is some questions are greedy+dp. I don't know if thats how I should call them but there are certain things better so we use that fact in dp and optimize. Also prefix calculation of previous iteration to optimize solution is also one. Also sometimes you will think that your current dp is TLE/MLE but actually you will not visit all states so you can use map<> and memoization to solve those. I think in the end alot depends on how to optimize further in hard questions.

  • »
    »
    4 месяца назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    Thank you for taking the time to share your experience and insights. Your explanation really helped me see the bigger picture of how to approach DP problems, especially the balance between greedy thinking, core DP patterns, and optimization. I really appreciate it.

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

Solve problems

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

Practice DP problems, consider them thoroughly. Solve the same problem in recursive, iterative tables approaches