Iterate from every position and find the maximum sum which is possible
int maxi = 0 ; for ( int i = 0 ; i < n ; i ++ ) { maxi = Math . Max ( maxi , func ( i , 0 , a , dp , n , x ) ) ; } return maxi ; }