<p>You are given 3 positive integers <code>zero</code>, <code>one</code>, and <code>limit</code>.</p>

<p>A <span data-keyword="binary-array">binary array</span> <code>arr</code> is called <strong>stable</strong> if:</p>

<ul>
	<li>The number of occurrences of 0 in <code>arr</code> is <strong>exactly </strong><code>zero</code>.</li>
	<li>The number of occurrences of 1 in <code>arr</code> is <strong>exactly</strong> <code>one</code>.</li>
	<li>Each <span data-keyword="subarray-nonempty">subarray</span> of <code>arr</code> with a size greater than <code>limit</code> must contain <strong>both </strong>0 and 1.</li>
</ul>

<p>Return the <em>total</em> number of <strong>stable</strong> binary arrays.</p>

<p>Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">zero = 1, one = 1, limit = 2</span></p>

<p><strong>Output:</strong> <span class="example-io">2</span></p>

<p><strong>Explanation:</strong></p>

<p>The two possible stable binary arrays are <code>[1,0]</code> and <code>[0,1]</code>.</p>
</div>

<p><strong class="example">Example 2:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">zero = 1, one = 2, limit = 1</span></p>

<p><strong>Output:</strong> <span class="example-io">1</span></p>

<p><strong>Explanation:</strong></p>

<p>The only possible stable binary array is <code>[1,0,1]</code>.</p>
</div>

<p><strong class="example">Example 3:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">zero = 3, one = 3, limit = 2</span></p>

<p><strong>Output:</strong> <span class="example-io">14</span></p>

<p><strong>Explanation:</strong></p>

<p>All the possible stable binary arrays are <code>[0,0,1,0,1,1]</code>, <code>[0,0,1,1,0,1]</code>, <code>[0,1,0,0,1,1]</code>, <code>[0,1,0,1,0,1]</code>, <code>[0,1,0,1,1,0]</code>, <code>[0,1,1,0,0,1]</code>, <code>[0,1,1,0,1,0]</code>, <code>[1,0,0,1,0,1]</code>, <code>[1,0,0,1,1,0]</code>, <code>[1,0,1,0,0,1]</code>, <code>[1,0,1,0,1,0]</code>, <code>[1,0,1,1,0,0]</code>, <code>[1,1,0,0,1,0]</code>, and <code>[1,1,0,1,0,0]</code>.</p>
</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= zero, one, limit &lt;= 1000</code></li>
</ul>

# MOD=10**9+7
# class Solution:
#     def numberOfStableArrays(self, zero: int, one: int, limit: int) -> int:
#         @cache
#         def f0(l,c0):
#             if c0<0: return 0
#             if l==0: return c0==0
#             return sum(f1(x,c0-(l-x)) for x in range(max(0,l-limit),l))%MOD
#         @cache
#         def f1(l,c0):
#             if c0<0: return 0
#             if l==0: return c0==0
#             return sum(f0(x,c0) for x in range(max(0,l-limit),l))%MOD
#         l=zero+one
#         return (f0(l,zero)+f1(l,zero))%MOD

MOD=10**9+7
class Solution:
    def numberOfStableArrays(self, zero: int, one: int, limit: int) -> int:
        l=zero+one
        f0=[[0]*(2+zero) for _ in range(1+l)]
        sf0=[[0]*(2+zero) for _ in range(1+l)]
        f1=[[0]*(2+zero) for _ in range(1+l)]
        sf1=[[0]*(2+zero) for _ in range(1+l)]
        f0[0][0]=sf0[0][0]=1
        f1[0][0]=sf1[0][0]=1
        for l in range(1,l+1):
            for c0 in range(0,zero+1):
                f0[l][c0]=sf1[l-1][c0-1]
                f1[l][c0]=sf0[l-1][c0]
                sf0[l][c0]=(sf0[l-1][c0]+f0[l][c0]-(f0[l-limit][c0] if l-limit>=0 else 0))%MOD
                sf1[l][c0]=(sf1[l-1][c0-1]+f1[l][c0]-(f1[l-limit][c0-limit] if l-limit>=0 and c0-limit>=0 else 0))%MOD
        return (f0[l][zero]+f1[l][zero])%MOD
174200