#K86727. Unique Leaf Patterns in a Grid

    ID: 36929 Type: Default 1000ms 256MiB

Unique Leaf Patterns in a Grid

Unique Leaf Patterns in a Grid

In this problem, you are given an N x M grid. Each cell in the grid can either contain a leaf or not. Two leaf patterns are considered different if there is any cell where one pattern has a leaf and the other does not. Your task is to determine the number of unique leaf patterns possible in the grid.

For grids with only one row or one column, the answer is simply \(2^{\text{number of cells}}\). For larger grids, some cases are pre-determined:

  • A 2 x 2 grid has 6 unique patterns.
  • A 3 x 2 grid or a 2 x 3 grid has 26 unique patterns.
  • A 3 x 3 grid has 112 unique patterns.

You are to write a program that reads the dimensions of the grid from standard input and prints the number of unique leaf patterns to standard output.

inputFormat

The input consists of a single line with two space-separated integers (N) and (M) (1 ≤ N, M ≤ 10), representing the number of rows and columns of the grid, respectively.

outputFormat

Output a single integer representing the number of unique leaf patterns in the grid.## sample

2 2
6