Coloring a Rectangle
Time limit2sMemory limit512 MB
Count colorings of an N x M grid where every colored cell has an even number of colored side-neighbors.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Bit manipulation, Implementation
- Solved
- No attempts yet
Problem
A rectangle of size is divided into unit squares. Write a program that counts the ways to color its cells so that both conditions below hold.
- Every cell is either colored or empty.
- For each colored cell, the number of colored cells that share a side with it is even.
Empty cells carry no condition. Coloring no cell at all counts as one way.
The picture below is an example with and . Yellow cells are colored and black cells are empty.

Given and , count the colorings.
Input
The first line contains and . (, )
Output
Print the number of colorings modulo 1,000,000,007 on the first line.
Hint
For and the 8 colorings below are possible.
