SRM554 Div2 Medium(500) TheBrickTowerMediumDivTwo
TheBrickTowerMediumDivTwo
全探索。
#include <vector> #include <algorithm> using namespace std; class TheBrickTowerMediumDivTwo{public: vector <int> find( vector <int> heights ) { int n = (int)heights.size(); int m = 99999999; vector<int> ans; vector<int> v; for ( int i=0; i<n; i++ ) v.push_back(i); do { int d = 0; for ( int i=0; i<n-1; i++ ) d += max(heights[v[i]],heights[v[i+1]]); if ( d<m ) { m = d; ans = v; } } while ( next_permutation(v.begin(),v.end()) ); return ans; }};