Given a 3 x n board, find the number of ways to fill it with 2 x 1 dominoes.
Following are all the 3 possible ways to fill up a 3 x 2 board.
Here is one possible way of filling a 3 x 8 board. You have to find all the possible ways to do so.
Input : 2 Output : 3 Input : 8 Output : 153 Input : 12 Output : 2131
At any point while filling the board, there are three possible states that the last column can be in:
An = No. of ways to completely fill a 3 x n board. (We need to find this) Bn = No. of ways to fill a 3 x n board with top corner in last column not filled. Cn = No. of ways to fill a 3 x n board with bottom corner in last column not filled.
Note: The following states are impossible to reach:
Note: Even though Bn and Cn are different states, they will be equal for same ‘n’. i.e Bn = Cn
Hence, we only need to calculate one of them.
Final Recursive Relations are:
- Tiling Problem
- Find the original matrix when largest element in a row and a column are given
- Number of subsequences with zero sum
- Find the maximum possible value of a[i] % a[j] over all pairs of i and j
- Count pairs of non-overlapping palindromic sub-strings of the given string
- Queries to check if substring[L...R] is palindrome or not
- Find the number of divisors of all numbers in the range [1, n]
- Find the number of sub arrays in the permutation of first N natural numbers such that their median is M
- Program to find the maximum difference between the index of any two different numbers
- Interactive Problems in Competitive Programming
- Find triplet such that number of nodes connecting these triplets is maximum
- Find the minimum number of operations required to make all array elements equal
- Convert the undirected graph into directed graph such that there is no path of length greater than 1
- Lazy Propagation in Segment Tree | Set 2
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.