#P9318. [EGOI 2022] Lego Wall / 乐高墙
[EGOI 2022] Lego Wall / 乐高墙
Background
Day 1 Problem B.
The statement is translated from EGOI2022 legowall.
Problem Description
There are two types of Lego bricks, with sizes and (width, height, length). You have an unlimited number of both types, and all bricks of the same type are indistinguishable.

A brick is always used in the correct orientation. The faces on all sides are made of the same material, and there is no difference other than the size.
We say that two bricks are locked if and only if one brick is directly above the other. We say that two bricks and are connected if and only if there exists a sequence of bricks such that every pair of adjacent bricks and are locked. We say that a set of bricks is connected if and only if every pair of bricks in the set is connected.
You want to build a Lego wall of size such that the wall has no holes and is connected. Below is an example of a Lego wall:

On the other hand, the following Lego wall is not connected, so it is not acceptable:

How many different ways are there to build a Lego wall that has no holes and is connected? The answer may be very large; output it modulo .
Note that a mirrored version of a Lego wall (rotated by ) is considered different from the original, unless they look exactly the same.
Input Format
One line with two integers — the width and height of the Lego wall.
Output Format
One line with one integer, the number of ways modulo .
2 2
3
3 3
12
5 7
1436232
Hint
Explanation for Sample
The three valid constructions are shown below:

Constraints
For all testdata, , , and .
- Subtask 1 ( points): .
- Subtask 2 ( points): .
- Subtask 3 ( points): .
- Subtask 4 ( points): .
- Subtask 5 ( points): .
- Subtask 6 ( points): no additional constraints.
Translated by ChatGPT 5
