bottom up approach to calculate score
public static double score ( int n , List < int > A , int k ) { if ( memo [ n , k ] > 0 ) return memo [ n , k ] ; double sum = 0 ; for ( int i = n - 1 ; i > 0 ; i -- ) { sum += A [ i ] ; memo [ n , k ] = Math . Max ( memo [ n , k ] , score ( i , A , k - 1 ) + sum / ( n - i ) ) ; } return memo [ n , k ] ; } public static double largestSumOfAverages ( List < int > A , int K ) { int n = A . Count ; double sum = 0 ; for ( int i = 0 ; i < memo . GetLength ( 0 ) ; i ++ ) { for ( int j = 0 ; j < memo . GetLength ( 1 ) ; j ++ ) memo [ i , j ] = 0.0 ; } for ( int i = 0 ; i < n ; i ++ ) { sum += A [ i ] ;