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 ways to divide circle using N non-intersecting chords
- Maximum sum in a 2 x n grid such that no two elements are adjacent
- Minimum number of deletions to make a sorted sequence
- Minimum steps to delete a string after repeated deletion of palindrome substrings
- Gold Mine Problem
- Count number of ways to fill a "n x 4" grid using "1 x 4" tiles
- Compute nCr % p | Set 1 (Introduction and Dynamic Programming Solution)
- Find number of solutions of a linear equation of n variables
- Count even length binary sequences with same sum of first and second half bits
- Tiling Problem
- Minimum number of squares whose sum equals to given number n
- Count all possible paths from top left to bottom right of a mXn matrix
- Coin Change | DP-7
- Program for Fibonacci numbers
- Largest Sum Contiguous Subarray