All problems
0834HardDynamic ProgrammingPrefix Sum

Steady Punch Card Layouts

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3130Find All Possible Stable Binary Arrays II

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A punch card is a single row of cells. Every cell is either a blank or a mark. A card is steady when all three hold:

  • it carries exactly zero blanks;
  • it carries exactly one marks;
  • no run of limit + 1 cells in a row is all blanks or all marks.

Two cards are different when some position carries a different kind of cell. Return how many steady cards exist, taken modulo 1000000007.

Examples

Example 1

Input
zero = 1, one = 2, limit = 1
Output
1

With a cap of one, no two neighbouring cells may match. Only the card reading mark, blank, mark satisfies that while carrying one blank and two marks.

Example 2

Input
zero = 2, one = 2, limit = 1
Output
2

A cap of one forces the kinds to alternate, so the card either opens with a blank or opens with a mark, giving two steady cards.

Example 3

Input
zero = 3, one = 3, limit = 2
Output
14

Cards such as blank, blank, mark, blank, mark, mark are steady, since no three cells in a row match. Counting every such card gives this many.

Constraints

  • 1 <= zero <= 1000
  • 1 <= one <= 1000
  • 1 <= limit <= 1000

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def steady_layouts(zero: int, one: int, limit: int) -> int:
Java
public int steadyLayouts(int zero, int one, int limit)
September 7
Apply