3130. Find All Possible Stable Binary Arrays II
3130. Find All Possible Stable Binary Arrays II
Description
You are given 3 positive integers zero
, one
, and limit
.
A binary array arr
is called stable if:
- The number of occurrences of 0 in
arr
is exactlyzero
. - The number of occurrences of 1 in
arr
is exactlyone
. - Each subarray of
arr
with a size greater thanlimit
must contain both 0 and 1.
Return the total number of stable binary arrays.
Since the answer may be very large, return it modulo 10^9 + 7
.
Example 1:
1 | Input: zero = 1, one = 1, limit = 2 |
Example 2:
1 | Input: zero = 1, one = 2, limit = 1 |
Example 3:
1 | Input: zero = 3, one = 3, limit = 2 |
Constraints:
1 <= zero, one, limit <= 1000
Hints/Notes
- need to find the O(1) state transition equation for dp
Solution
Language: C++
1 | class Solution { |