Created
June 4, 2021 11:35
-
-
Save nachiketkanore/9a2290798358dd57fbd26e64235971a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int go(int L, int R){ | |
if(L > R) | |
return 0; | |
if(L == R) | |
return a[L]; | |
int &ans = dp[L][R]; | |
if(ans != -1) | |
return ans; | |
int c1 = a[L] + go(L+1,R); | |
int c2 = a[L]*a[L+1] + go(L + 2, R); | |
int c3 = a[R] + go(L,R-1); | |
int c4 = a[R]*a[R-1] + go(L, R - 2); | |
ans = max({c1, c2, c3, c4}); | |
return ans; | |
} | |
// final_ans = go(1, n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment