Created
February 18, 2012 18:40
-
-
Save yasith/1860625 to your computer and use it in GitHub Desktop.
Stars energy, dp
This file contains hidden or 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
map<vector<int>, int > dp; | |
int rec(vector<int> v){ | |
if(dp.find(v) != dp.end()){ | |
return dp[v]; | |
} | |
if(v.size() == 2){ | |
return 0; | |
} | |
int max_en = 0; | |
for(int i = 1; i < v.size() - 1; i++){ | |
int el = v[i]; | |
v.erase(v.begin() + i); | |
int val = v[i-1] * v[i+1] + rec(v); | |
v.insert(v.begin() + i, el); | |
max_en = max(val, max_en); | |
} | |
return max_en; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment