#P2051. Placement of Cannons on a Chessboard

    ID: 15333 Type: Default 1000ms 256MiB

Placement of Cannons on a Chessboard

Placement of Cannons on a Chessboard

In this problem, you are given a chessboard with n rows and m columns. You need to place a number of cannons (possibly 0) on the board so that no cannon is able to attack another.

The movement (attack) rule for a cannon in Chinese chess is as follows: One cannon can attack another if and only if they are located in the same row or the same column and there is exactly one piece between them. Since the board is empty except for the cannons you place, a cannon placed in cell (i, j) can attack another cannon in the same row (or column) if and only if the set of cannons chosen in that row (or column) contains exactly three cannons when considering the two endpoints and the one in between. Equivalently, if a row (or column) has three or more cannons, then there will exist a pair of cannons for which the number of cannons strictly between them is exactly one, and these two cannons will be able to attack each other. Thus, in every row and every column, the number of cannons must be at most 2.

Your task is to count the total number of ways to choose a subset of cells (possibly empty) to place cannons so that in each row and each column there are at most 2 cannons. Note that since cannons do not attack along empty cells, any row or column with 0, 1, or 2 cannons is allowed.

Note: Even if two cannons in the same row or column are not adjacent (i.e. there are empty cells between them), this does not matter; the only concern is when there exists exactly one cannon placed between any two cannons in that row or column. For any row (or column), if there are 0, 1, or 2 cannons then there is no possibility of having exactly one cannon between any two cannons. However, if there are 3 or more cannons, then some pair will have exactly one cannon between them, and the configuration is invalid.

inputFormat

The input consists of a single line containing two integers n and m separated by a space, representing the number of rows and columns, respectively.

outputFormat

Output a single integer representing the number of valid ways to place the cannons on the board satisfying the given restrictions.

sample

1 1
2