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
- Perform range sum queries on string as per given condition
- Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers
- Count of all possible Paths in a Tree such that Node X does not appear before Node Y
- Mix Order Traversal of a Binary Tree
- Minimum number of operations required to reduce N to 0
- Generate all possible permutations of a Number divisible by N
- Construct an Array of Strings having Longest Common Prefix specified by the given Array
- Count of Distinct Substrings occurring consecutively in a given String
- Sum of bit differences for numbers from 0 to N | Set 2
- Mimimum number of leaves required to be removed from a Tree to satisfy the given condition
- Farthest distance of a Node from each Node of a Tree
- Size of all connected non-empty cells of a Matrix
- Sum of Nodes and respective Neighbors on the path from root to a vertex V
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.