2
* @param {number[]} nums6
var largestSumOfAverages = function (nums, k) {8
const len = nums.length;10
const sum = new Array(len).fill(0);11
// set nums first to first of sum14
// set every item of sum to the sum of the previous and the corresponding item of nums15
for (let i = 1; i < len; i++) {16
sum[i] = sum[i - 1] + nums[i];19
// set dynamic programming20
const dp = new Array(k + 1).fill("").map(() => new Array(len).fill(0));22
// according to the meaning of the problem, set the value of dp23
for (let i = 0; i < len; i++) {24
dp[1][i] = sum[i] / (i + 1);26
for (let i = 1; i <= k; i++) {27
dp[i][i - 1] = sum[i - 1];29
for (let i = 2; i <= k; i++) {30
for (let j = i; j < len; j++) {31
for (let m = j - 1; m >= i - 2; m--) {34
dp[i - 1][m] + (sum[j] - sum[m]) / (j - m)41
return dp[k][len - 1];