https://leetcode.com/problems/largest-sum-of-averages/
const int maxn = 1e2+10;
double dp[maxn][maxn][maxn];
int sum[maxn];
class Solution {
public:
int getSum(int x, int y)
{
return sum[y]-(x==0?0:sum[x-1]);
}
double largestSumOfAverages(vector<int>& A, int K) {
memset(sum, 0, sizeof(sum));
memset(dp, 0, sizeof(dp));
int len = A.size();
sum[0] = A[0];
for(int i=1; i<len; i++){
sum[i] = sum[i-1]+A[i];
}
for(int i=0; i<len; i++){
for(int j=i; j<len; j++){
dp[i][j][j-i+1] = getSum(i,j)*1.0;
dp[i][j][1] = getSum(i, j)*1.0/(j-i+1);
}
}
for(int k=2; k<=K; k++){
for(int i=0; i<len; i++){
for(int j=i+k-1; j<len; j++){
for(int s=i; s<j; s++){
dp[i][j][k] = max(dp[i][j][k], dp[i][s][k-1]+getSum(s+1, j)*1.0/(j-s));
}
}
}
}
return dp[0][len-1][K];
}
};