Tiling problem 2

Unable to come up with a logic for this proble using recursions,
kindly dry run it for me and explain the logic

Hello @mkidwai74 In this problem you have figured the base cases correct that if n<m then return 1 and if n==m return 2. The recurrsion relation will be that if n>m then add the two recursions . One with same function but n as n-1 and the other will be same function but with n= n-m . Now this will the two cases one in which tile are placed vertically will be where n=n-1 and the one where tiles are placed horizontally will be where n=n-m . And also i will recommend that rather than forming a recurrence relation try to take a array of size n+1 and fill it from index i= 1 where size of n =1 till index i= n and where each index has the total possible way of that case on that index i.

Imagine you have a floor of size n × m and you are given tiles of size 1× m.
Now you can either place the tiles vertically. Where a tile can be either place vertically,meaning it will only occupy a cell of width 1 and a complete height of M

there are 3 possibilities:

n>m - here you can place a tile vertically(left with n-m,m) as well as horizontally(left with n-1,m).
n==m then there are always 2 ways - horizontally or vertically.
n<m here you have only 1 choice,that is to place tile horizontally, so 1 way only.
Also mere recursion won’t help in passing all test cases, you have to use DP.caf18112a2649438288c4b7241d8a71fbf68703e_2_690x485 d14d1e193790ab4eb31f981a54a4a82f5617a676_2_388x500

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.