WOSS Dual Olympiad 2022 Team Round P3: Bobby and the Sidewalk

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 2.0s
Memory limit: 256M

Authors:
Problem types

Bobby had a crazy day at school today. On the way back home, Bobby is accompanied by his oldest sister. Since she is a mathematics major in university, she poses a math question to Bobby about the sidewalk they are walking on. The sidewalk consists of an N by M grid consisting of blue, red, and yellow tiles, where N,M are positive integers. N represents the number of rows, while M represents the number of columns. Each of these tiles has dimensions of 1×1. Bobby's sister notes that a blue tile is never horizontally adjacent to a red tile. In this case, two tiles are horizontally adjacent if they share their left or right border with one another. She asks Bobby to tell her the number of possible sidewalks satisfying these conditions.

Help Bobby find the number of ways to tile an N×M sidewalk with blue, red, and yellow 1×1 tiles such that a blue tile is never horizontally adjacent to a red tile. Note that a blue tile is allowed to be vertically adjacent to a red tile.

Constraints

1N1012

1M106

Note: You will not be required to pass the sample cases to proceed to the subtasks.

Subtask 1 [10%]

N=1

1M10

Subtask 2 [20%]

1N5

1M10

Subtask 3 [40%]

1N106

1M106

Subtask 4 [30%]

No additional constraints.

Input Specification

The first and only line contains two space-separated integers, N and M.

Output Specification

Output will consist of a single integer: the number of possible sidewalks satisfying the given conditions, modulo 109+7 (i.e., find the remainder when the answer is divided by 109+7).

Sample Input 1

Copy
1 3

Sample Output 1

Copy
17

Explanation of Sample 1

The possible arrangements are: BBB, BBY, BYB, BYR, BYY, RRR, RRY, RYB, RYR, RYY, YBB, YBY, YRR, YRY, YYB, YYR, YYY.

Sample Input 2

Copy
2 4

Sample Output 2

Copy
1681

Comments

There are no comments at the moment.