This page is still under construction.

Parts of this page are still being built. What you see may change.

Mondrian's Dream

Interview

Time limit1sMemory limit256 MB

Summary
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 22 and height 11 (a 2×12 \times 1 domino).

Given the size of the large rectangle, write a program that counts the number of ways to tile it with 2×12 \times 1 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 hh and the width ww of the large rectangle, separated by a space. (1≤h,w≤111 \le h, w \le 11)

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 2×12 \times 1 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.

Examples1

  1. Example 1

    Input
    1 2
    1 3
    1 4
    2 2
    2 3
    2 4
    2 11
    4 11
    0 0
    
    Expected output
    1
    0
    1
    2
    3
    5
    144
    51205