Mondrian's Dream
InterviewTime limit1sMemory limit256 MB
Count the number of ways to tile an h by w rectangle (up to 11 by 11) with 2 by 1 dominoes, for several test cases.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Bit manipulation, Brute force, Implementation
- Solved
- No attempts yet
Problem
The Dutch painter Piet Mondrian was fascinated by squares and rectangles.
One day he dreamed of completely filling a large rectangle using small rectangles of width and height (a domino).
Given the size of the large rectangle, write a program that counts the number of ways to tile it with dominoes. Each domino may be placed either horizontally or vertically, and dominoes must not overlap one another or extend outside the rectangle.
Input
The input consists of several test cases. Each test case is a single line containing the height and the width of the large rectangle, separated by a space. ()
The last line contains two zeros and is not processed.
Output
For each test case, print on its own line the number of ways to tile the large rectangle with dominoes.
The large rectangle has a fixed orientation (top/bottom and left/right are distinguished), so tilings that map onto each other by rotation or reflection are counted as distinct.