4
public int fnc(int a[], int i, int j, int sum) {5
// System.out.println(i+" "+j);13
if (dp[i][j] != 0) return dp[i][j];16
int ans = Integer.MIN_VALUE;18
for (int index = i; index <= j; index++) {20
if (temp > sum - temp) {21
ans = Math.max(ans, ((sum - temp) + fnc(a, index + 1, j, sum - temp)));22
} else if (temp < sum - temp) {23
ans = Math.max(ans, temp + fnc(a, i, index, temp));29
sum - temp + fnc(a, index + 1, j, sum - temp), temp + fnc(a, i, index, temp)));35
public int stoneGameV(int[] stoneValue) {36
int n = stoneValue.length;38
for (int ele : stoneValue) sum += ele;40
return fnc(stoneValue, 0, n - 1, sum);