<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers and an integer <code>k</code>.</p>

<p><strong>Partition</strong> the array into two ordered <strong>groups</strong> such that each element is in exactly <strong>one</strong> group. A partition is called great if the <strong>sum</strong> of elements of each group is greater than or equal to <code>k</code>.</p>

<p>Return <em>the number of <strong>distinct</strong> great partitions</em>. Since the answer may be too large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>

<p>Two partitions are considered distinct if some element <code>nums[i]</code> is in different groups in the two partitions.</p>

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

<pre>
<strong>Input:</strong> nums = [1,2,3,4], k = 4
<strong>Output:</strong> 6
<strong>Explanation:</strong> The great partitions are: ([1,2,3], [4]), ([1,3], [2,4]), ([1,4], [2,3]), ([2,3], [1,4]), ([2,4], [1,3]) and ([4], [1,2,3]).
</pre>

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

<pre>
<strong>Input:</strong> nums = [3,3,3], k = 4
<strong>Output:</strong> 0
<strong>Explanation:</strong> There are no great partitions for this array.
</pre>

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

<pre>
<strong>Input:</strong> nums = [6,6], k = 2
<strong>Output:</strong> 2
<strong>Explanation:</strong> We can either put nums[0] in the first partition or in the second partition.
The great partitions will be ([6], [6]) and ([6], [6]).
</pre>

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

<ul>
	<li><code>1 &lt;= nums.length, k &lt;= 1000</code></li>
	<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
</ul>

class Solution:
    def countPartitions(self, nums: List[int], k: int) -> int:
        """
        * nums[ii]: an array of resources
        * when partition to two groups  (A, B), this is equivalent to each item is choose or skip, 
          picked in Group A, skipped (automatically) in Group B
        * whenever you pick/skip something and count ways/optimize profit/cost -> DP
        * whenever you have a big anser space and need MOD -> think of DP
        * whenever you have two partition groups -> consider they are symmentric
        * whenever you have two partitions, think of ttl = A + B 
        """
        N=len(nums)
        M=int(1e9)+7

        if sum(nums) < 2*k: return 0

        nums=[0]+nums # have (N+1) in size 

        dp = [[0]*k for _ in range(N+1)] # N resources (0~N-1). sum to 0~(k-1)     
        dp[0][0]=1
        
        for ii in range(N): #from 1~N (after dummy insertion)
            for jj in range(k):  #sum from 0~(k-1)
                dp[ii+1][jj] = (dp[ii+1][jj]+ dp[ii][jj])%M
                if jj >= nums[ii+1]:
                    dp[ii+1][jj] = (dp[ii+1][jj] + dp[ii][jj-nums[ii+1]])%M
        
        ttl = pow(2, N)%M
        invalid = sum(dp[-1])%M

        return (ttl-invalid*2%M)%M
619