Tiling dominoes | Dynamic programming

Поділитися
Вставка
  • Опубліковано 15 лип 2024
  • Walkthrough of dynamic programming on how to tile dominoes on a grid.
    Problem:
    open.kattis.com/problems/trit...
    Source code:
    github.com/williamfiset/Algor...
    Video slides:
    github.com/williamfiset/algor...
    Website:
    www.williamfiset.com

КОМЕНТАРІ • 67

  • @WilliamFiset-videos
    @WilliamFiset-videos  4 роки тому +7

    For those of you looking for a challenge, check out this tiling problem:
    open.kattis.com/problems/tray
    The problem is very similar except that it adds two elements of complexity:
    1) 1x1 tiles are introduced
    2) Some cells are banned

    • @rohitbohra4248
      @rohitbohra4248 4 роки тому +1

      Hey for this problem, I am following the similar idea. Here there will be more possible combinations for a particular dp state(a column). I have eliminated the banned cells(set it to INT_MIN) by using a hashmap and checking if a state(out of those 8 as stated in video) is possible or not. I am stuck from this point on.
      Could you give a hint or something on this problem?
      Thank you:)

  • @puneetkumarsingh1484
    @puneetkumarsingh1484 4 роки тому +29

    The problem just blew my mind! Then solution blew my mind even more! I was like speechless when I saw that each columns tiling pattern could be mapped to 0 to 7 in a binary fashioned way! Thanks a lot.
    This problem definitely opens mind about how a problem can be approached.

    • @puneetkumarsingh1484
      @puneetkumarsingh1484 4 роки тому +3

      @WilliamFiset I think another channel is uploading your videos. Is it your channel or have you provided it with the permission ua-cam.com/video/1A6OYsKmL1U/v-deo.html

  • @Garentei
    @Garentei 4 роки тому +19

    It always helps to to see some sort of visualization instead of understanding it in the abstract :), great video.

  • @adityapandey2514
    @adityapandey2514 3 роки тому +2

    was stuck for a long time, very very informative,really the best possible explanation,
    instant share with my friends practicing dp. Thank you keep making these videos.

  • @CrystalSergeant
    @CrystalSergeant 4 роки тому +1

    amazing. Please keep doing this. Good DP videos are lacking on youtube.

  • @tanvirhasan4912
    @tanvirhasan4912 4 роки тому +1

    Would love more on DP . Great explanation.

  • @jackthehammer2245
    @jackthehammer2245 4 роки тому

    What a cool question and cool DP solution.

  • @asma-pe3rx
    @asma-pe3rx 4 роки тому +3

    Well this was a bitmask dp problem with the best explanation.

  • @sakshamsethi4123
    @sakshamsethi4123 4 роки тому +4

    Possibly best tiling video ever

  • @CodeCraftWithVinayak
    @CodeCraftWithVinayak 4 роки тому

    I always wait for ur videos WillamFiset

  • @egor.okhterov
    @egor.okhterov 3 роки тому +3

    Variations of this problem:
    1. There field is N x M.
    2. There are two domino types: 2x1 and 1x1.
    3. There is limited number of dominos: A dominos of type 2x1, B dominos of type 1x1.
    4. There are dominos of weird shapes like “r” or 2x2 square.

  • @madhukiranattivilli2321
    @madhukiranattivilli2321 3 роки тому

    Wow! Superbly derived solution. Thankyou.

  • @codewithamir21
    @codewithamir21 2 роки тому

    Most intuitive approach for this problem 🔥💖

  • @kirtanitaliya7631
    @kirtanitaliya7631 4 роки тому +3

    need more videos on DP. Amazing explanations. more, more, more....

  • @jole0
    @jole0 3 роки тому

    This blew my mind! Thank you so much

  • @gautammishra96
    @gautammishra96 3 роки тому

    Awesome explanation!

  • @anshumansrivastava8108
    @anshumansrivastava8108 3 роки тому +1

    what can be more better than this wow...

  • @timothygao9442
    @timothygao9442 4 роки тому

    Most underrated channel tbh

  • @niyatisrivastava5407
    @niyatisrivastava5407 2 роки тому

    the best possible solution! thanks

  • @andrea1955
    @andrea1955 4 роки тому

    Your videos are great! You should consider making one about Push-Relabel. Keep up the good work!

  • @HiteshSethiya
    @HiteshSethiya 4 роки тому

    You're a great tutor! Let me know if you're starting any mentorship programs.

  • @thibozaide4429
    @thibozaide4429 4 роки тому +1

    Great video ! thanks a lot :D

  • @shreshan1
    @shreshan1 2 роки тому

    Wow great explanation thanks

  • @RedionXhepa
    @RedionXhepa 4 роки тому

    Excelleny video ! Thanks?

  • @zhaoc033
    @zhaoc033 3 роки тому +1

    What if there are more than 3 columns? How would the state transition work?

  • @innokentiyromanchenko1450
    @innokentiyromanchenko1450 Рік тому

    this is brilliant

  • @syedahmed6568
    @syedahmed6568 4 роки тому

    what softwares do you use to create these videos?

  • @chiragyadav4455
    @chiragyadav4455 4 роки тому +2

    Please upload videos on Convex Hull Algorithms.

  • @nk_goyal
    @nk_goyal 2 роки тому

    Well instead of determining states, a simple solution is to just sum up prev states and then F(n)=3*F(n-2)+2*sum
    int numTilings(int n)
    {
    vector arr(n+1,0);
    arr[0]=1;
    int sum=0;
    for (int i=2;i

    • @ZeroBit
      @ZeroBit 2 роки тому

      it's not right, ig

  • @1vader
    @1vader 4 роки тому +1

    I solved it quite differently but my submissions always failed because I forgot to output 1 for width 0 >.>
    I did a recursion on the width:
    x = 3*f(n-2)
    for (i = 2; i < width - 2; i += 2) x += 2 * f(i)
    x += 2
    The thing is that the whole rectangle is always filled by two types of blocks:
    - 2*3 blocks of which there are 3 possible types
    - 2*(2x) blocks of which there are 2 possible types for every x always arranged like this:
    11 55 88
    2 33 66 9
    2 44 77 9
    or the same thing upside down where the middle parts can be repeated to add 2 to the width.
    This is even fast enough to work without DP.
    Oh and if width % 2 == 1 i.e. the width is odd I just output 0 immediately.

  • @himeshgupta6478
    @himeshgupta6478 2 роки тому

    AWESOME!!!!!!!!!!

  • @ayushprakash3890
    @ayushprakash3890 2 роки тому

    awesome

  • @harshsrivastava1819
    @harshsrivastava1819 Рік тому

    love from ghaziabad💕💕💕💕

  • @bonopo
    @bonopo 3 роки тому +1

    Fun fact: you can do this in log (n) with matrix exponentation (and I think there is a formula to calculate domino tiling as well)

  • @professorsnapp
    @professorsnapp 4 роки тому +1

    Thanks my brain said 🤯

  • @niteshgarg464
    @niteshgarg464 3 роки тому

    Why did the initialisation of dp[0][7] became one. As there is no row behind it it should not be possible ? only dp[0][3] and dp[0][6] should have been initialised to 1 right and all rest 0.

  • @factsheet4930
    @factsheet4930 3 роки тому

    I did it much more simply, but thank you for showing me this question nonetheless!

  • @CarlosMartinez-jf3rn
    @CarlosMartinez-jf3rn 4 роки тому

    great

  • @satakshipandey6729
    @satakshipandey6729 3 роки тому +1

    When we are calculating state 7 from state 0, it should be dp[i][7] += dp[i-2][0] instead of dp[i][7] += dp[i-1][0] or am I. missing something?

    • @tuhinmukherjee8141
      @tuhinmukherjee8141 3 роки тому

      No, the area difference between dp[i-2][0] and dp[i][7] is 3x3 if you notice carefully.
      However, one problem lies in the fact that dp[i][7] can be constructed from dp[i-1][0] in 3 different ways. Why do we not account for that?

  • @preethaparasuraman5317
    @preethaparasuraman5317 4 роки тому +1

    Nice Explaination. Thank you. However i couldn't understand how states 2 and 5 are not possible, but 3 and 7 are possible.

    • @WilliamFiset-videos
      @WilliamFiset-videos  4 роки тому +5

      Great question! This might have merited more of an explanation, so let me write it out here.
      If you have a look at 12:12 when we go from state 2 in column 0 to state 5 in column 1, you will notice that state 2 in column 0 is an impossible state with 1 tile. Similarly, state 5 in column 0 is an impossible state. Both of these impossible states dp[0][2] and dp[0][5] will have an initial value of 0, so dp[1][2] and dp[1][5] will also have a value of 0, and so will dp[i][2] and dp[i][5]. It's safe to remove state 2 and 5 since: 1) no other states depend on states 2 and 5 for their number of tilings 2) states 2 and 5 only depend on each other 3) dp[i][2] and dp[i][5] are always 0

    • @ragingpahadi
      @ragingpahadi 4 роки тому

      @@WilliamFiset-videos i guess picture is worth thousand words and your explanation was on target. Thanks for making such beautiful video

  • @tuhinmukherjee8141
    @tuhinmukherjee8141 3 роки тому +1

    Can't dp[i][7] be constructed from dp[i-1][0] in 3 different ways? Clearly, one of them as pointed out in this video is to tile three of them horizontally. The two remaining was are : Tile two of them vertically and another one horizontally underneath them and following symmetry, the opposite. Someone please help me out regarding this!

    • @MayankKumar-mn3dg
      @MayankKumar-mn3dg 2 роки тому

      That case is already being considered when transitioning from say dp[i-1][6].

  • @kejiadai7716
    @kejiadai7716 4 роки тому +3

    I have difficulty understand why is only dp[0][7] set to be 1 as the initial value. Could someone explain? Thnaks a lot

    • @rithwiksrk462
      @rithwiksrk462 4 роки тому +2

      how many ways is it possible to make an empty grid?

    • @jole0
      @jole0 3 роки тому +1

      I also struggled a little with it, but if you apply the algorithm you will see that the only state that is affected by 0 state is 7.
      The line is ´´dp[i][7] += dp[i-1][0];´´.
      He is simply extending this logic.
      Another way to do this is to instead let the code do this for you. Increase the size of the array by one (so it is now n+2), and instead of dp[0][7]=1, you can do dp[0][0]=1, if that makes more sense to you. PS: I got AC with this solution.

  • @DinHamburg
    @DinHamburg 3 роки тому +2

    I came to find the explanation for sin and cos in the kasteleyn domino-tiling formula - yuk

  • @guptagaurav916
    @guptagaurav916 2 роки тому +1

    Why is dp[0][7] = 1 ?

  • @Drcphd21341
    @Drcphd21341 3 роки тому +1

    Excellent video, however there is one case which is not expanded on. Theoretically, state 1 can come from state 0, by placing 1 vertical and 1 horizontal domino. How come this is not accounted for?

    • @Drcphd21341
      @Drcphd21341 3 роки тому

      I guess that the arrangements of Dominos I described above is already counted when state 6 is considered in the creation of state 1. So considering state 0 would be overcounting states. Correct me If I'm wrong

  • @aminuolawale1843
    @aminuolawale1843 3 роки тому

    Can't state 7 be generated from state 1? Or have I misunderstood something?

    • @it42titikshagupta9
      @it42titikshagupta9 2 роки тому

      Actually State 7 cannot be generated by state 1 because adding 2*1 tile to state 1 will create dp[i-1][7] and not dp[i][7] and similar is the case of state 4

  • @GOODBOY-vt1cf
    @GOODBOY-vt1cf 3 роки тому +1

    2:00

  • @GOODBOY-vt1cf
    @GOODBOY-vt1cf 3 роки тому +1

    2:20

  • @treyquattro
    @treyquattro 3 роки тому

    it turns into a neural net!

  • @GOODBOY-vt1cf
    @GOODBOY-vt1cf 3 роки тому

    2:39

  • @lakshmanvengadesan9096
    @lakshmanvengadesan9096 3 роки тому

    Ok, I completely understand this, this is a great video, but how do I think of this in front of the interviewer??? 😖😖😔

  • @dipenpatel5226
    @dipenpatel5226 4 роки тому +1

    would you say this could appear in a interview?

    • @egor.okhterov
      @egor.okhterov 3 роки тому

      Variations of this problem could definitely appear