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 email@example.com. 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.
- Minimum number of jumps to reach end
- Maximum size square sub-matrix with all 1s
- Total number of possible Binary Search Trees and Binary Trees with n keys
- Longest Increasing Subsequence Size (N log N)
- Efficient program to print all prime factors of a given number
- Count all possible paths from top left to bottom right of a mXn matrix
- Program for nth Catalan Number
- Count number of binary strings without consecutive 1's
- Count Possible Decodings of a given Digit Sequence
- Count all possible walks from a source to a destination with exactly k edges
- Count ways to reach the n'th stair
- Count number of ways to reach a given score in a game
- How to print maximum number of A's using given four keys
- Count possible ways to construct buildings
- Count numbers from 1 to n that have 4 as a digit