Dynamic Programming lecture #3 - Line of wines

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ธ.ค. 2024

ความคิดเห็น • 126

  • @Errichto
    @Errichto  5 ปีที่แล้ว +97

    Pls hit the bell button. And subscribe to my 2nd channel for very boring streams: th-cam.com/users/errichto2

    • @diablo3879
      @diablo3879 5 ปีที่แล้ว +11

      Done.
      Please keep making DP videos they're really helpfull.

    • @amitbhatt575
      @amitbhatt575 5 ปีที่แล้ว +4

      They are not boring sir , they are actually very helpful , thanks again

    • @enlite
      @enlite 5 ปีที่แล้ว +4

      Where is link for leetcode question?

    • @DHRUVNARAYANSINGH
      @DHRUVNARAYANSINGH 4 ปีที่แล้ว +2

      Implementation www.hackerearth.com/practice/notes/dynamic-programming-i-1/

  • @shobhitbanshi4192
    @shobhitbanshi4192 5 ปีที่แล้ว +43

    i has been struggling to do programming but i never gave up and it's been 3 months of regular coding i learn something new everyday .. Its not too late to do it

  • @fbru02
    @fbru02 5 ปีที่แล้ว +14

    This is great !! Really you have a gift for explaining . Watched the video at 1.5x and it was perfect speed.

  • @iprakhar22
    @iprakhar22 5 ปีที่แล้ว +6

    It is very important to look at concepts from all the possible perspectives in order to get a better understanding and to be able to solve very different problems.
    This was such a nice video that explains a beginner level problem from all the angles. Thank you Kamil

  • @nahidhossain2058
    @nahidhossain2058 5 ปีที่แล้ว +3

    Please, keep uploading videos on this topic. Your videos are so useful.

  • @antonykelvin6645
    @antonykelvin6645 5 ปีที่แล้ว +6

    The first 3 parts were great :D
    Waiting for the 4rth one

  • @nikola123
    @nikola123 3 ปีที่แล้ว +5

    A very insightfull approach to teaching dynamic programming. I'd love to see a video about some advanced dp optimizations, like divide and conquer dp, or convex hull trick.

  • @m1kr0kosmos
    @m1kr0kosmos 3 ปีที่แล้ว +8

    Heyyy just got in to MIT, thank you for helping me so much. Looking forward to building some fun stuff :D

  • @lovishmadhu912
    @lovishmadhu912 4 ปีที่แล้ว

    Dude appreciate your Work.
    I bet no one can explain dynamic programming terms and ways to solve it more patiently and clearly.

  • @nova2577
    @nova2577 4 ปีที่แล้ว

    The best. Much much better than those who only try to sell their websites or product.

  • @dharmanshah1239
    @dharmanshah1239 5 ปีที่แล้ว +7

    Hey guys!! Just to make sure you get it, at 14:06 it's "year 1" instead of "interval 1". Enjoy!!

  • @abhinav4279_
    @abhinav4279_ 3 ปีที่แล้ว

    The video covered wide variety of approaches and did require a lot of thinking on viewer part as well.
    Thanks @errichto for creating such great educational content.💫

  • @BeastMaster-dq8vt
    @BeastMaster-dq8vt 5 ปีที่แล้ว +10

    Errichto the mvp

  • @DarshanSenTheComposer
    @DarshanSenTheComposer 5 ปีที่แล้ว +1

    Big thank you for spending the time in making this video. Very well explained. Enjoyed it. :)

  • @meht8
    @meht8 4 ปีที่แล้ว +2

    Very good explanation

  • @arianphilips5777
    @arianphilips5777 4 ปีที่แล้ว

    Errichto you are the best bro you have the talent and the way to teach others your knowledge that's simple beautiful when someone explains complex things easily, I really love this dynamic programming series I'll be waiting the 4th lecture, please take it on consideration. Good vibes Errichto.

  • @turntoallah2773
    @turntoallah2773 5 ปีที่แล้ว +2

    I am very grateful to you.From Bangladesh

  • @kunal_chand
    @kunal_chand 5 ปีที่แล้ว +39

    Create a playlist of "Dynamic Programming Lectures".
    It will be easier for us to find the tutorials.

    • @Errichto
      @Errichto  5 ปีที่แล้ว +24

      Good idea, will do that tomorrow!

    • @adarshsharmanit356
      @adarshsharmanit356 4 ปีที่แล้ว +9

      @@Errichto sir, Will you make more videos on Dynamic programming ??

  • @soumyadeeppal6486
    @soumyadeeppal6486 5 ปีที่แล้ว +1

    Sir you should continue this series.We are larning a lot

  • @GeorgeHFonseca
    @GeorgeHFonseca 2 ปีที่แล้ว

    Laughed a lot at the ending: "I hope you understood all the 3 solutions ... If not, try watching the video again." 😂😂😂
    Yes, sir, I did it a few times until finally got it. Great video btw

  • @ajr1791ze
    @ajr1791ze 5 ปีที่แล้ว

    good that you gave recursive intution this time along with iterative. pls. continue it.

  • @thomasbarnekow1281
    @thomasbarnekow1281 3 ปีที่แล้ว

    Thanks for the nice video! I struggled a bit with the order of states described at 15:10. Thus, I would offer an easier-to-understand and more natural order of computing solution I (bottom-up) (mentioned at 5:00 and presented at 15:10). Based on the understanding that the profit for a row of length K is only dependent on the profits of rows of length K-1, the outer loop could go from length in 2..N, since we deal with rows of length 1 as part of the initialization. The inner loop then goes from L in 1..(N-length+1). Then, R simply equals left + length - 1 and dp[L][R] is computed as before.

  • @cindytrinhsridykhan6375
    @cindytrinhsridykhan6375 4 ปีที่แล้ว

    Thanks for the nice problem and great explanations !

  • @diegonayalazo
    @diegonayalazo 2 ปีที่แล้ว

    Thanks for sharing young Master

  • @Divij09
    @Divij09 ปีที่แล้ว

    8:13 How is the L-1 case handled? We're only considering removal from right but not left

  • @nicolasg6095
    @nicolasg6095 5 ปีที่แล้ว +30

    Hi, Errichto. As always great video, and lots of high value material. I have a problem though, when you compute the year: For the first year, L=1, and R=N, for the second year either (L=2 and R=N) or (L=1 and R=N-1). With your formula Y=N-(L-1)-(N-R), I can't find the correct answer. Should the fomula be Y = L + (N-R)? Or do I miss something?

    • @Errichto
      @Errichto  5 ปีที่แล้ว +20

      Oh, you are right. My formula computes the length of the interval [L, R] in some complicated way. It would work for solution III, but not here. Thanks for spotting a mistake!

    • @farhan787
      @farhan787 4 ปีที่แล้ว +4

      ​@@Errichto ​ it'd be really helpful if you could provide the code for all 3 implementations of this problem.

  • @shivangraina9698
    @shivangraina9698 5 ปีที่แล้ว +2

    Thank you so much errichto..

  • @sumantopal558
    @sumantopal558 5 ปีที่แล้ว +1

    make this series more active, atleast 1-2 episode every week

    • @Errichto
      @Errichto  5 ปีที่แล้ว +5

      I will do my best but can't guarantee 1-2 episodes weekly.

  • @jaakjpn
    @jaakjpn 5 ปีที่แล้ว

    Nice problem! When solving I came up with a different solution to Errichto's solutions. Instead of dp variables L and R I used variables L and year. In this case dp[L][year] denotes what is the maximum we can earn by the given year if L left wines are sold. Initialization is dp[L][year]=0 and the progression is push style, from the current year to the next.
    Nice property of this solution is that only the last year needs to be stored (i.e, resulting in O(N) memory). It is quite intuitive to implement as the DP progresses through time (years).

  • @VocalWithShubham
    @VocalWithShubham 4 ปีที่แล้ว

    @Errichto . Please make more and more dp videos like your previous dp videos including these with complete thought process.Also make series of videos for graphs from beginning to advanced. I completely like your way of teaching. I want more and more videos should be out by you so that I can think like you in every problems.

  • @nifengjujuzhang8429
    @nifengjujuzhang8429 5 ปีที่แล้ว +3

    WOW... theese three DP tutorials you made are so inspiring. I was struggling in algorithm course and the lecturer in my uni don't explain the thinking process. After watching these three tutorials you made, I solved all the DP problems in the assignment

    • @Errichto
      @Errichto  5 ปีที่แล้ว +1

      AtCoder Beginner Contests are cool and interesting. And Codeforces is biggest for Competitive Programming in general.

    • @nifengjujuzhang8429
      @nifengjujuzhang8429 5 ปีที่แล้ว

      @@Errichto Will be looking into it. Thank you!

  • @AdamTheBen
    @AdamTheBen 4 ปีที่แล้ว

    Dude great content. Keep at it!

  • @farhan787
    @farhan787 4 ปีที่แล้ว +3

    ​@Errichto ​ it'd be really helpful if you could provide the code for all 3 implementations of this problem.

  • @Player-ub9tg
    @Player-ub9tg 4 ปีที่แล้ว +1

    Thank you so far

  • @Geez99569
    @Geez99569 5 ปีที่แล้ว +2

    next level thinking :)

  • @anshulyadav269
    @anshulyadav269 9 หลายเดือนก่อน +1

    how many here have attended interviews at FANG (Facebook,Amazon, Netflix,Google)companies and got DP questions in their processes ?

  • @omagarwal4769
    @omagarwal4769 4 ปีที่แล้ว +1

    at 7:09 why did u not considered the case for dp[L+1][R]=max(dp[L+1][R],dp[L][R] +p[L]*Y)?

  • @existenence
    @existenence 4 ปีที่แล้ว +1

    It's crazy to me how similar the fundamental idea of reinforcement learning is to that of dynamic programming.

  • @navalrox
    @navalrox 4 ปีที่แล้ว +4

    I’ve tried around 30 DP problems on leetcode and watched tons of lectures on DP as well including yours but I’m still not able to identify what should be the state(here sum) and what should be the parameters(here L,R). As you said you can simply keep what is asked in the question to be the state say maximum value or number of sets. But i have a really hard time deciding what the parameters for a state should be. Even if it obvious sometimes. Also I have difficulty with iterative solutions as you showed in this example we should have L+1 computed so the arrow should be N to 1 which I’m not able to think on my own. What do you suggest I do about it? Is there a resource I can study from to understand what I’m missing better or practice makes perfect?
    Thanks. :)

  • @wazza9425
    @wazza9425 5 ปีที่แล้ว +1

    hi Errrichto, I was wondering about the top down solution of this problem. So if dp[L][R -1] = dp[L][R] + P[R].Y then dp[L + 1][R] = dp[L][R] + P[L].Y right? So isnt it that I have to implement two separate formula in an iterative method? Like do I need to have 2 separate for loops, 1 for dp[L][R - 1] and 1 for dp[L + 1][R] ? Thanks in advance : D

  • @jbbouz
    @jbbouz 5 ปีที่แล้ว +3

    Awesome video, very helpful stuff! I am struggling with the implementation for the bottom up approach, is there any chance you could show me the full code for this implementation. Thanks! love your videos

  • @Shikharchaudhary007
    @Shikharchaudhary007 4 ปีที่แล้ว +1

    in Solution 2, why is dp[L][R-1]=max({dp[L][R]+p[R]*Y, dp[L-1][R-1]+p[L-1]*Y, dp[L][R-1]}) not right?

  • @ascyrax8507
    @ascyrax8507 4 ปีที่แล้ว

    errichto u r the best.

  • @asdfghjkl36958
    @asdfghjkl36958 3 ปีที่แล้ว

    Is there a systematic way to determine if a problem should be approached with greedy vs DP? Or do you just try to work through the example with greedy, and if it breaks, move on to DP? If the provided example still works for greedy it might be tricky to find a contradiction.

  • @quickinsights9037
    @quickinsights9037 4 ปีที่แล้ว +1

    Can you please give me the code for the Solution 2, I don't understand in which order to compute dr[L][R-1]

  • @shivamagarwal1630
    @shivamagarwal1630 4 ปีที่แล้ว

    Approach 3 will be a good solution if the problem is changed to a stream problem where you do not know the size of the array initially, as the solution doesn't depend on the array size.
    Approach 1 and 2 are dependent on size of array

  • @reformed_attempt_1
    @reformed_attempt_1 4 ปีที่แล้ว

    this is amazing

  • @camperjett
    @camperjett 2 ปีที่แล้ว

    @errichto DP lecture 4 when? I am waiting

  • @abhishekgautam2693
    @abhishekgautam2693 5 ปีที่แล้ว +8

    can you make next video about dp with strings like maximum substring with all distinct characters in a string or minimum length of substring containing all characters in original string. I don't know how to approach these kind of problems one of my colleage said it could be done by dp[N][26] but i would like to know the thinking process.

    • @Errichto
      @Errichto  5 ปีที่แล้ว +2

      I get what you're saying. Will keep it in mind.

  • @SingularisVisum
    @SingularisVisum 5 ปีที่แล้ว +1

    Found out about you from Joma Tech. During the interview you mentioned that your strong math background helped you skyrocket through Cormen's algorithms book. Specifically what math books in what specific math subjects did you study prior to learning algorithms from the Cormen book? Thanks!

    • @Errichto
      @Errichto  5 ปีที่แล้ว +2

      I learned math in school. So, some random Polish school books.

    • @SingularisVisum
      @SingularisVisum 5 ปีที่แล้ว

      @@Errichto Thanks man! Totally subscibed👍
      Do you have any advice on what are the specific math subjects you find important to know prior to hitting the algorithms book?

  • @toekneema
    @toekneema 4 ปีที่แล้ว

    Isn't R-1 going to be undefined when R=L at the begging of each nested loop?

  • @Looped_13
    @Looped_13 4 ปีที่แล้ว +1

    Sir please post more DP tutorials🙏🙏🙏

  • @gustavorangel729
    @gustavorangel729 2 ปีที่แล้ว

    Has anyone found where can we practice this problem? I found it at Codechef, but it says "The contest problem is not available for accepting solutions).

  • @Nevergiveup-lr9oc
    @Nevergiveup-lr9oc 5 ปีที่แล้ว

    Please make more videos on dp. I am weak on it

  • @shivamjalotra7919
    @shivamjalotra7919 5 ปีที่แล้ว

    Nice explanation, I am starting with dp. So as a beginner, I compute the result with the greedy approach. From here how I am supposed to think that the greedy approach will not be the optimal one? Do I first code it out and then think of Dp or just take smaller examples and see from hit and trail that greedy breaks and I should go for dp?

    • @Errichto
      @Errichto  5 ปีที่แล้ว +3

      You should think: how would this greedy approach be correct? Can making this decision now hurt me in the future (after a few steps)? If yes, maybe let's try to create a counterexample. It's a bit of intuition plus thinking about proof or counterexample.

  • @zhongyanhuang693
    @zhongyanhuang693 4 ปีที่แล้ว

    Will there be Dynamic Programming Lecture #4?

  • @rohan8arora
    @rohan8arora 5 ปีที่แล้ว

    Thank you!!

  • @georgedrooj8800
    @georgedrooj8800 4 ปีที่แล้ว

    when will you make more dp videos ???

  • @nishuone161
    @nishuone161 5 ปีที่แล้ว

    Hey Errichto, great tutorial! Do you have the actual code for this exercise? I understood the big picture but im still a bit confused on the actual implementation. Much appreciated.

  • @indistantdreams
    @indistantdreams 3 หลายเดือนก่อน

    Can you link the problem on some online judge so that I can submit my solution??

  • @ANKITKUMAR-en4ue
    @ANKITKUMAR-en4ue 4 ปีที่แล้ว

    Please tell the sudo code for second and third approach

  • @akshayagarwal3460
    @akshayagarwal3460 4 ปีที่แล้ว

    can you make a video on digit dp also

  • @MoeZarella
    @MoeZarella 5 ปีที่แล้ว

    this might've been asked before, but what do you use to draw by hand? a touchscreen or one of those drawing pads?

    • @Errichto
      @Errichto  5 ปีที่แล้ว

      Wacom drawing table. Also, you can read FAQ: github.com/Errichto/youtube/wiki/FAQ

  • @divyanshuagrawal2699
    @divyanshuagrawal2699 3 ปีที่แล้ว

    12:13 - Solution

  • @shr3y4sh
    @shr3y4sh 3 ปีที่แล้ว

    Will this series be updated ?

  • @hetanthakkar4532
    @hetanthakkar4532 5 ปีที่แล้ว

    hey i find clrs very tough as its questions are too mathy(atleast for me) any suggestion? should i improve on my math knowledge an stick to clra or find some other book(in this case plz do recommend one)

    • @Errichto
      @Errichto  5 ปีที่แล้ว

      I don't know your level but if something is very tough, then indeed consider switching to easier source. Use google.

    • @hetanthakkar4532
      @hetanthakkar4532 5 ปีที่แล้ว

      @@Errichto okay thanks.

  • @rakshithyadhav7274
    @rakshithyadhav7274 5 ปีที่แล้ว

    I love coding but when i dont know a solution to a problem i open editorial or other submissions and learn the algorithm and implement it . Does this help or should try even more to get the solution on my own . Thanks keep up your good work.

    • @Errichto
      @Errichto  5 ปีที่แล้ว +6

      Just make sure to try to do it yourself first. Then it's good to check the editorial and learn what is the solution. Read more here: github.com/Errichto/youtube/wiki/How-to-practice%3F

  • @ankitpunia4722
    @ankitpunia4722 3 ปีที่แล้ว

    I am not able to implement solution 2
    any help.....

  • @tvrao123
    @tvrao123 ปีที่แล้ว

    have a knock of complicating simple ones

  • @TechManAkhil
    @TechManAkhil 4 ปีที่แล้ว

    Is the dp series over?

  • @aparichitsingh384
    @aparichitsingh384 5 ปีที่แล้ว +1

    Nice video!
    Can you please make videos for some advanced topic you thought to be useful for ICPC....

    • @Errichto
      @Errichto  5 ปีที่แล้ว

      I make various videos ;p some are useful for icpc, inluding this one (but ofc. it's not that hard)

  • @AshikaUmanga
    @AshikaUmanga 5 ปีที่แล้ว

    is it possible to backtrack and print the selling order for the maximum profit ?

    • @Errichto
      @Errichto  5 ปีที่แล้ว +1

      Yes. It's a standard technique to remember the best previous state.

    • @AshikaUmanga
      @AshikaUmanga 5 ปีที่แล้ว

      @@Errichto thank you for the reply. Is is possible in a future lecture explain how to do this? There's only few content in the internet on this topic.

    • @Errichto
      @Errichto  5 ปีที่แล้ว

      @@AshikaUmanga Maybe I will do it. Now you can read about it here: codeforces.com/blog/entry/43256 (part about "Recovering the best solution for optimization problems
      ")

  • @vincesanchez7790
    @vincesanchez7790 5 ปีที่แล้ว

    Bro please make some Javascript Programming challenges
    keep it up Errichto :)

  • @akshayagarwal3460
    @akshayagarwal3460 4 ปีที่แล้ว

    How can we solve this problem using bottom up approach www.spoj.com/problems/BORW/
    I am unable to find its solutin using bottom up anywhere

  • @saitamagoku209
    @saitamagoku209 5 ปีที่แล้ว

    Can you make a video on tsp, bitmask dp & digit dp. It will be very helpful. Thank you

  • @chatrughanprasad7778
    @chatrughanprasad7778 4 ปีที่แล้ว +2

    Even after paying one can not get this type of information.

  • @VishalJangid1
    @VishalJangid1 4 ปีที่แล้ว

    Discord link is expired

  • @shubhamrana1390
    @shubhamrana1390 5 ปีที่แล้ว +1

    Please make a video on how to compute nCr quickly!

    • @shrad6611
      @shrad6611 5 ปีที่แล้ว

      you can easily do it with a concept that :
      nCr = (n-1)C(r-1) + (n-1)Cr
      and take dimension of dp as dp[n][r] its the best and efficient way to do it

    • @techwithwhiteboard3483
      @techwithwhiteboard3483 5 ปีที่แล้ว

      use a for loop with r as min r or n-r

  • @sahilsharma2952
    @sahilsharma2952 5 ปีที่แล้ว

    can anybody share the link to the problem?

    • @Errichto
      @Errichto  5 ปีที่แล้ว

      This problem isn't from any platform/contest.

    • @sahilsharma2952
      @sahilsharma2952 5 ปีที่แล้ว

      @@Errichto Should I try this on GeeksForGeeks?

    • @Errichto
      @Errichto  5 ปีที่แล้ว

      @@sahilsharma2952 I don't understand your question. Try what? Is this problem on GfG?

    • @sahilsharma2952
      @sahilsharma2952 5 ปีที่แล้ว +1

      @@Errichto Yes

    • @Errichto
      @Errichto  5 ปีที่แล้ว

      @@sahilsharma2952 You are right. www.geeksforgeeks.org/maximum-profit-sale-wines/

  • @gmmkeshav
    @gmmkeshav 4 ปีที่แล้ว

    sir why not greedy

  • @sug_madic7683
    @sug_madic7683 ปีที่แล้ว

    i personally hate my friends because they never started to code.

  • @monk4857
    @monk4857 4 ปีที่แล้ว

    great thank u

  • @timothygao9442
    @timothygao9442 4 ปีที่แล้ว +1

    Number of likes = people who want Errichto to continue this series👇

  • @saideepesh6036
    @saideepesh6036 5 ปีที่แล้ว +2

    Sir, do only gifted people (high iq) would succeed in becoming good at programming or normal person like me can do better by practicing it.

    • @Errichto
      @Errichto  5 ปีที่แล้ว +5

      What kind of question is this ;p you need some brain capacity to do any job that requires thinking. It doesn't mean you have to be a genius to become a programmer.

    • @saideepesh6036
      @saideepesh6036 5 ปีที่แล้ว

      @@Errichto kind of impostor syndrome that has been effecting me when I solve programming questions.

  • @akshayagarwal3460
    @akshayagarwal3460 4 ปีที่แล้ว

    can you make a video on digit dp also