getting run time error.
Tilling Problem-II
Hey @RULEREMPIRES
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.
Tile placed horizontally(one row is covered now recurse for remaining rows):-
countWays(n - 1, m)
Tile placed vertically if and only if :-
if(n - m >= 0) {
countWays(n - m, m)
}
Now where is the issue, try to visualize the case for 4*3.
there is a 4 * 3 floor, then you have a 1 * 3 tile.
Now if you place the tile horizontally then you have 3 * 3 floor left to tile.
So you make a call for say tiling(n - 1) i.e n - 1 rows left to tile.
Now one vertical call is made by you in the code. So your work is to add the horizontal call.
@RULEREMPIRES
Don’t take the modulo after the calculation is over it is serious case of overflow!!
So, make a global variable and declare MOD= 10^9 + 7
and then replace " return h + v;" with " return (h+v)%MOD;"
this is fine!!
Best regards from
-@rkrishna