Wooden Bridge
Time limit1sMemory limit1024 MB
Count the distinct bridges of W blocks whose total span is exactly L, where each block shifts by at most 1 unit from the one below, modulo 1e9+7.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem

A carpenter wants to build a wooden bridge across a river that is wide. The bridge is made of wooden blocks. Each block is 2 units long and 1 unit tall, and the blocks are joined together to form the bridge. For smooth passage, the horizontal overlap between each pair of vertically adjacent blocks must be 1 or 2 units long.
The carpenter wants the bridge to be as long as safely possible, so the distance from the left end of the bridge to the right end is exactly . Two bridges count as the same shape if shifting one left or right makes it match the other. Count the number of distinct bridge shapes that satisfy these conditions.
Input
The river width and the distance from the left end of the bridge to the right end are given.
Output
Print the number of distinct bridge shapes that satisfy the conditions, modulo .