Filling bookcase shelves problem using dynamic programming

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 ก.ย. 2024
  • Welcome to the video of Joey'sTech on a leetcode problem#1105 which is the filling bookcase shelves problem.
    Now, this DP problem has the same difficulty level as the Box Stacking problem and Text Justification problem so, make sure you pay attention while watching this video.
    I have done my best to keep you engaged with the explanation of this dynamic programming problem, so, you will have fun while learning to construct the dynamic programming
    algorithm of the filling bookcase shelves problem.
    I am saying this the first time since I started producing videos but watching this video of my dynamic programming tutorial will beneficial for you.
    Watching it twice will unlock more thinking doors in the mind.
    -------------------- Problem Statement ---------------------
    You got some books to store in a bookshelf. Assume that you have to build this bookshelf to store your books.
    You have to store books in the same order given in the question.
    There will be multiple book cases in this bookshelf, once they get full you need to construct a book case beneath it.
    The width of each book case is given to you in the variable shelf-width.
    Each book given to you has 2 attributes denoted by book[i][0] and book[0][i]
    book[i][0] represents the thickness of the book and book[0][i] represents its height.
    You can only place those books in the bookshelf whose combined thickness is less than or equal to the shelf_width variable.
    Like I mentioned earlier, once a book case is full you need to build another level of bookshelf whose height will be the maximum height of the books
    placed on that level
    You task is to build the bookshelf with the minimum height possible by fitting all the books in the racks.
    This means you need to find the minimum height of the bookshelf.
    Below is the book array and the value of shelf_width
    [ [ 1,1 ] , [ 2,3 ] , [ 2, 3 ], [ 1,1 ], [ 1,1 ], [ 1,1 ], [ 1,2 ] ]
    shelf_width = 4
    So, now let's solve this problem with the classic dynamic programming technique in this video.
    ---------------------------- Also Watch -------------------------
    Text justification problem dynamic programming
    • Step by step guide to ...
    Box stacking problem dynamic programming
    • Box stacking problem u...
    subset sum problem dynamic programming
    • Subset sum problem | T...

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

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

    Thanks

  • @chingchenghanji643
    @chingchenghanji643 2 ปีที่แล้ว +1

    Thank you my man, I searched up so many algorithms but I couldn't fully understand them, and you totally nailed it!

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

      Thanks Andrew for appreciating,,don't forget to subscribe.

  • @anushac1
    @anushac1 11 หลายเดือนก่อน

    Very good explanation. Only channel which covered this problem.

    • @joeystechpluscode
      @joeystechpluscode  11 หลายเดือนก่อน

      Thanks - do recommend joeystech to others

  • @shuvabhigupta976
    @shuvabhigupta976 3 ปีที่แล้ว +1

    Thanks for covering such difficult level questions with detailed explanation.

  • @anuragharsh2012
    @anuragharsh2012 3 ปีที่แล้ว +1

    Very helpful video, you explained it very well.

  • @shirazy1378
    @shirazy1378 3 ปีที่แล้ว +1

    I liked the video, thank you very much, the demonstration helped me!

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

      You are welcome and don’t forget to subscribe

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

    Great explanation!

  • @anishsuman1371
    @anishsuman1371 2 ปีที่แล้ว +1

    Bottom up dp of this guy is awesome

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

      Hey Anish, if ‘this guy’ is me then thank you very much

    • @anishsuman1371
      @anishsuman1371 2 ปีที่แล้ว +1

      @@joeystechpluscode yes it's you only I have seen whole dp playlist it's awesome

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

      @@anishsuman1371 thanks man...Good luck!

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

    awesome explanation

  • @abhi0707
    @abhi0707 9 หลายเดือนก่อน

    Java code :
    class Solution {
    public int minHeightShelves(int[][] books, int shelfWidth) {
    // for every book i, we try to figure out how many prev books can be kept in same shelf including book i
    int n=books.length;
    //dp[i] denotes minHeightShelves if we take first i books into consideration
    int[] dp=new int[n+1];
    for(int i=1;ishelfWidth)
    break;
    dp[i]=Math.min(dp[i],height+dp[j-1]);
    }
    }
    return dp[n];
    }
    }

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

    great one buddy keep going

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

    this method could never occur to me.. i was trying to memoize the problem with regular approach which was making it too complicated. Thanks for the video !

  • @ankitraj2283
    @ankitraj2283 7 หลายเดือนก่อน +1

    Am i only one unable to understand Problem statement ?

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

    Hi

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

    You people can not solve recursively you are smarter guys