dp
of size maxLength + 1
with all elements set to 0.dp[0]
to 1.i
from 1 to maxLength
.
a. If i
is greater than or equal to oneGroup
, add dp[i - oneGroup]
to dp[i]
.
b. If i
is greater than or equal to zeroGroup
, add dp[i - zeroGroup]
to dp[i]
.
c. Take the modulo of dp[i]
with 10^9 + 7
to prevent integer overflow.result
to 0.i
from minLength
to maxLength
.
a. Add dp[i]
to result
.
b. Take the modulo of result
with 10^9 + 7
.result
as the final answer.