Find All Possible Stable Binary Arrays I
Real-world version: Settled Control TapesThe statement here is our own: the same inputs, outputs and technique.
A punch machine writes a control tape one cell at a time. Each cell ends up holding either the value 0 or the value 1, and the finished tape must hold exactly zero cells of value 0 and exactly one cells of value 1, so its length is always zero + one.
The reader that consumes the tape loses synchronisation if it ever passes a long stretch of identical cells. A tape is therefore called settled when every maximal block of equal neighbouring cells holds at most limit cells; equivalently, nowhere on the tape do limit + 1 consecutive cells carry the same value.
Two tapes are different when they differ in at least one position. Count the settled tapes and report that count as a remainder after division by 1000000007.
Examples
Example 1
- Input
- zero = 2, one = 2, limit = 1
- Output
- 2
Writing a tape as its run of cell values, the settled tapes are `0101` and `1010`. Every block in each one holds a single cell, which is within `limit = 1`.
Example 2
- Input
- zero = 2, one = 3, limit = 2
- Output
- 7
The seven settled tapes are `01011`, `01101`, `10011`, `10101`, `10110`, `11001` and `11010`. Each holds two `0` cells and three `1` cells, and no block in any of them is longer than two.
Example 3
- Input
- zero = 4, one = 3, limit = 7
- Output
- 35
`limit = 7` is at least the tape length, so no arrangement can violate the block rule and every ordering of four `0` cells and three `1` cells counts.
Constraints
- 1 <= zero <= 200
- 1 <= one <= 200
- 1 <= limit <= 200
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def number_of_stable_arrays(zero: int, one: int, limit: int) -> int:public int numberOfStableArrays(int zero, int one, int limit)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Stone Game IIReal-world version: Front Loaded Tray HaulMedium
- Jump Game VIIReal-world version: Pontoon Crossing With A Hop RangeMedium
- Maximum Frequency After Subarray OperationReal-world version: Most Dials Reading k After One NudgeMedium
- Split Array Largest SumReal-world version: Balanced TruckloadsHard