#P9318. [EGOI 2022] Lego Wall / 乐高墙

[EGOI 2022] Lego Wall / 乐高墙

Background

Day 1 Problem B.

The statement is translated from EGOI2022 legowall.

CC BY-SA 3.0

Problem Description

There are two types of Lego bricks, with sizes 1×1×11\times 1\times 1 and 2×1×12\times 1\times 1 (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 b0b_0 and bkb_k are connected if and only if there exists a sequence of bricks b0,b1,,bkb_0,b_1,\ldots,b_k such that every pair of adjacent bricks bi1b_{i-1} and bib_i 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 w×h×1w\times h\times 1 such that the wall has no holes and is connected. Below is an example of a 4×3×14\times 3\times 1 Lego wall:

On the other hand, the following 4×3×14\times 3\times 1 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 109+710^9+7.

Note that a mirrored version of a Lego wall (rotated by 180180^\circ) is considered different from the original, unless they look exactly the same.

Input Format

One line with two integers w,hw,h — the width and height of the Lego wall.

Output Format

One line with one integer, the number of ways modulo 109+710^9+7.

2 2
3
3 3
12
5 7
1436232

Hint

Explanation for Sample 11

The three valid constructions are shown below:


Constraints

For all testdata, 1w2.5×1051\le w\le 2.5\times 10^5, 2h2.5×1052\le h\le 2.5\times 10^5, and w×h5×105w\times h\le 5\times 10^5.

  • Subtask 1 (1414 points): w=2w=2.
  • Subtask 2 (1212 points): h=2h=2.
  • Subtask 3 (1818 points): w,h100w,h\le 100.
  • Subtask 4 (3030 points): w700w\le 700.
  • Subtask 5 (2020 points): h700h\le 700.
  • Subtask 6 (66 points): no additional constraints.

Translated by ChatGPT 5