Skip to content

Instantly share code, notes, and snippets.

@yasith
Created February 18, 2012 18:40
Show Gist options
  • Save yasith/1860625 to your computer and use it in GitHub Desktop.
Save yasith/1860625 to your computer and use it in GitHub Desktop.
Stars energy, dp
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