
How might I approach this problem? I am thinking I try to put tiles, then if I cant put any more, I need to backtrack … but how do I know how much to backtrack? Also after putting a tile, how might I (the code) decide which next tile to fill and with which type of tile?
use this recurrence :
F(N) = F(N - 1) + F(N - 3)with base case :
F(0) = F(1) = F(2) = 1Here, F(N) represents no of ways of tiling a 3XN grid with 3X1 or 1X3 tiles.
if you place a 3X1 tile, then you just need to solve for
F(N - 1).if you place a 1×3 tile, then you cant place a 3×1 tile under
it. Basically, you will have to place a set of three 1×3 tiles
together, hence you solve for
F(N - 3).Take the sum, and you get the recurrence i mentioned above.
Hope this helps 🙂