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.
- Count number of ways to fill a "n x 4" grid using "1 x 4" tiles
- Number of ways to make binary string of length N such that 0s always occur together in groups of size K
- Count number of increasing subsequences of size k
- Number of ways to reach Nth floor by taking at-most K leaps
- Count of sub-sets of size n with total element sum divisible by 3
- Queries on number of Binary sub-matrices of Given size
- Number of arrays of size N whose elements are positive integers and sum is K
- Maximum number of trailing zeros in the product of the subsets of size k
- Count number of ways to get Odd Sum
- Count number of ways to jump to reach end
- Count number of ways to partition a set into k subsets
- Count number of ways to cover a distance
- Count number of ways to arrange first N numbers
- Count the number of ways to traverse a Matrix
- Count number of ways to reach a given score in a Matrix