<p>You are given an integer array <code>nums</code> and an integer <code>k</code>. You can partition the array into <strong>at most</strong> <code>k</code> non-empty adjacent subarrays. The <strong>score</strong> of a partition is the sum of the averages of each subarray.</p>

<p>Note that the partition must use every integer in <code>nums</code>, and that the score is not necessarily an integer.</p>

<p>Return <em>the maximum <strong>score</strong> you can achieve of all the possible partitions</em>. Answers within <code>10<sup>-6</sup></code> of the actual answer will be accepted.</p>

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

<pre>
<strong>Input:</strong> nums = [9,1,2,3,9], k = 3
<strong>Output:</strong> 20.00000
<strong>Explanation:</strong> 
The best choice is to partition nums into [9], [1, 2, 3], [9]. The answer is 9 + (1 + 2 + 3) / 3 + 9 = 20.
We could have also partitioned nums into [9, 1], [2], [3, 9], for example.
That partition would lead to a score of 5 + 2 + 6 = 13, which is worse.
</pre>

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

<pre>
<strong>Input:</strong> nums = [1,2,3,4,5,6,7], k = 4
<strong>Output:</strong> 20.50000
</pre>

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

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

struct Helper {
    size_t operator()(const pair<int8_t, int8_t> &P) const {
        return hash<short>()(short(INT8_MAX) * P.first + P.second);
    }
};
unordered_map<pair<int8_t, int8_t>, long double, Helper> memo;
unordered_map<pair<int8_t, int8_t>, bool, Helper> vis;
short arr[100];
int8_t n;
long double solve(int8_t idx, int8_t rem){
    if(vis[{idx, rem}]) return memo[{idx, rem}];
    if(rem == 1){
        long double avg = 0.0;
        for(int8_t i = idx; i < n; i++){
            avg += arr[i];
        }
        avg /= (n - idx);
        vis[{idx, rem}] = true;
        return memo[{idx, rem}] = avg;
    }
    long double avg = 0.0, mx = 0.0;
    for(int8_t i = idx; i < n; i++){
        avg += arr[i];
        mx = max(mx, avg / (i + 1 - idx) + solve(i + 1, rem - 1));
    }
    vis[{idx, rem}] = true;
    return memo[{idx, rem}] = mx;
}
long double solve(int idx, int rem){
    return solve(int8_t(idx), int8_t(rem));
}
class Solution {
public:
    double largestSumOfAverages(vector<int>& nums, int k) {
        n = nums.size();
        memo.clear(), vis.clear();
        for(int i = 0; i < n; i++) arr[i] = nums[i];
        return solve(0, k);
    }
};
15900