rows rows, each exactly length units long. You have bricks of height 1 with the lengths listed in pieces (all different); there is an unlimited supply of each length, and bricks cannot be rotated.
The wall is solid if no two adjacent rows have a joint between bricks at the same position. The two ends of the wall do not count as joints.
Count the ways to build a solid wall. Two ways differ if some row has its bricks in a different sequence. Return the answer modulo 10⁹ + 7.rows=2, length=4, pieces=[1, 3] → 2
A row can be 1+1+1+1, 1+3 or 3+1. Only "1+3 below 3+1" and "3+1 below 1+3" make a solid wall: their joints sit 1 and 3 units from the edge and never line up.
rows=3, length=2, pieces=[2] → 1
Every row is a single brick of length 2 with no inner joints, so three such rows make a solid wall.
rows=1, length=5, pieces=[3, 4] → 0
Bricks of length 3 and 4 cannot fill a row of length exactly 5.
rows ≤ 100length ≤ 10pieces.length ≤ 10pieces[i] ≤ 10pieces are distinctrows=2, length=4, pieces=[1, 3]
2
Run checks the first 3 tests in your browser. Submit checks all 122 tests on the server, hidden ones included.