Tilling problem 2

Only 1 test case passing, kindly tell whats wrong.

hi @ujj1804_1156aee80205d0bf
u will have to use the concept of dynamic programming to overcome the problem of overlapping subproblems…
refer this code -->

Sir actually this problem was in recursion so i tried it using recursion .
Can you please explain that why m is taken as second paramater in both the function calls
x=fun(n-1,m); //When the tile is placed horizontally
y=fun(n-m,m); //When the brick is placed vertically

and also is y = (n-m,m-1) correct ? because when we place a tile vertically m-1 space would be left .

hi @ujj1804_1156aee80205d0bf
refer this diagram–>


Hope it will clear your doubt…

Yes sir clear, it means when we have placed one tile , we have to find ways to place tiles in remaining part only as that placed tile will have one way of getting placed , so we dont change m in the function call.

Like in the horizontal placing we can form a stack of tiles till the top in 1 way and the remaining tiles can be placed in n-m ways

right?

yes, correct @ujj1804_1156aee80205d0bf
we place one tile (either horizontally or vertically), and then recursively check for the remaining portion left… we need to pass m as parameter as we need to use it for base case as well as while placing the tiles horizontally…

Ok sir thanks. Doubt clear.

1 Like

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.