Given a floor of size n x m and tiles of size 1 x m. The problem is to count the number of ways to tile the given floor using 1 x m tiles. A tile can either be placed horizontally or vertically.
Both n and m are positive integers and 2 < = m.
Input : n = 2, m = 3 Output : 1 Only one combination to place two tiles of size 1 x 3 horizontally on the floor of size 2 x 3. Input : n = 4, m = 4 Output : 2 1st combination: All tiles are placed horizontally 2nd combination: All tiles are placed vertically.
This problem is mainly a more generalized approach to the Tiling Problem.
Approach: For a given value of n and m, the number of ways to tile the floor can be obtained from the following relation.
| 1, 1 < = n < m count(n) = | 2, n = m | count(n-1) + count(n-m), m < n
Number of ways = 5
Time Complexity: O(n)
Auxiliary Space: O(n)
This article is contributed by Ayush Jauhari. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count number of ways to fill a "n x 4" grid using "1 x 4" tiles
- Value of continuous floor function : F(x) = F(floor(x/2)) + x
- Tile Stacking Problem
- Number of ways to reach Nth floor by taking at-most K leaps
- Minimum cost to reach the top of the floor by climbing stairs
- Number of ways to make binary string of length N such that 0s always occur together in groups of size K
- Count ways to divide circle using N non-intersecting chords
- Count ways to reach a score using 1 and 2 with no consecutive 2s
- Count ways to reach the nth stair using step 1, 2 or 3
- Count number of ways to reach a given score in a game
- Count number of ways to cover a distance
- Count number of ways to partition a set into k subsets
- Count number of ways to reach destination in a Maze
- Count number of ways to jump to reach end
- Count number of ways to reach a given score in a Matrix
- Count number of ways to get Odd Sum
- Count number of ways to cover a distance | Set 2
- Count the number of ways to divide N in k groups incrementally
- Count the number of ways to give ranks for N students such that same ranks are possible
- Count number of ways to convert string S to T by performing K cyclic shifts