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 last remaining element after repeated removal of odd and even indexed elements alternately
- Count minimum number of moves to front or end to sort an array
- Maximum subsequence sum such that no K elements are consecutive
- Count possible splits of sum N into K integers such that the minimum is at least P
- Node whose removal minimizes the maximum size forest from an N-ary Tree
- Paths requiring minimum number of jumps to reach end of array
- Length of longest increasing absolute even subsequence
- Count balanced nodes present in a binary tree
- Print alternate nodes from all levels of a Binary Tree
- Print nodes of a Binary Search Tree in Top Level Order and Reversed Bottom Level Order alternately
- Count N digits numbers with sum divisible by K
- Maximize length of longest increasing prime subsequence from the given array
- Longest increasing subsequence which forms a subarray in the sorted representation of the array
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.