<p>Given an integer array <code>nums</code> and an integer <code>k</code>, split <code>nums</code> into <code>k</code> non-empty subarrays such that the largest sum of any subarray is <strong>minimized</strong>.</p>

<p>Return <em>the minimized largest sum of the split</em>.</p>

<p>A <strong>subarray</strong> is a contiguous part of the array.</p>

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

<pre>
<strong>Input:</strong> nums = [7,2,5,10,8], k = 2
<strong>Output:</strong> 18
<strong>Explanation:</strong> There are four ways to split nums into two subarrays.
The best way is to split it into [7,2,5] and [10,8], where the largest sum among the two subarrays is only 18.
</pre>

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

<pre>
<strong>Input:</strong> nums = [1,2,3,4,5], k = 2
<strong>Output:</strong> 9
<strong>Explanation:</strong> There are four ways to split nums into two subarrays.
The best way is to split it into [1,2,3] and [4,5], where the largest sum among the two subarrays is only 9.
</pre>

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

<ul>
	<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
	<li><code>0 &lt;= nums[i] &lt;= 10<sup>6</sup></code></li>
	<li><code>1 &lt;= k &lt;= min(50, nums.length)</code></li>
</ul>

class Solution:
    def splitArray(self, nums: List[int], k: int) -> int:
        ndd = lambda: defaultdict(ndd)

        n = len(nums)
        dp = ndd()
        dp[0][0] = 0
        for i in range(1, n + 1):
            dp[i][0] = dp[i - 1][0] + nums[i - 1]
        
        def dd_to_d(dd):
            if isinstance(dd, defaultdict):
                dd = {k: dd_to_d(v) for k, v in dd.items()}
            return dd
        # print(dd_to_d(dp))

        for j in range(1, k):
            for i in range(j + 1, n + 1):
                tmp_min = float("inf")
                right_sum = 0
                for l in range(1, i - j + 1):
                # print(i, j)
                    right_sum += nums[i - l]
                    if right_sum > tmp_min:
                        break
                    left_min = dp[i - l][j - 1]
                    # print(i, j, l, right_sum, tmp_min)
                    if max(right_sum, left_min) < tmp_min:
                        tmp_min = max(right_sum, left_min)
                dp[i][j] = tmp_min
            # print(dd_to_d(dp))

        return dp[n][k - 1]

19100