Language: C++

#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;

#define MAX 12

double sqs[MAX][MAX] = {{0,}};

class Cake{
public:
	Cake():r(0),used(false){};
	int r;
	bool used;
	bool operator<(const Cake &t) const{
		return r < t.r;
	}
};

bool check(int p[], int n, int w){
	double t = 0;

	t += p[0];
	for(int i = 0; i < n-1; i++){
		t += 2.0*sqrt((double)p[i]*p[i+1]);
	}
	t += p[n-1];

	return t <= w;
}

bool solve2(int p[], int pos, int w, Cake cakes[], int n, bool greater){
	if( pos == n ){
		return check(p,n,w);
	}else{
		for(int i = 0; i < n; i++){
			if( (greater ? p[pos-1] <= cakes[i].r : p[pos-1] >= cakes[i].r) && !cakes[i].used ){
				p[pos] = cakes[i].r;
				cakes[i].used = true;
				if( solve2( p, pos+1, w, cakes, n, !greater) ) return true;
				cakes[i].used = false;
			}
		}
		return false;
	}
}

bool solve(int p[], int n, int w, int r[]){
	/*
		High Speed but not alphameric order.
		genperm1 from http://www5.airnet.ne.jp/tomy/cpro/pe1.htm (C) Tomy
	*/
	double tw;
	int *c,*pc,*q,k,t;

	c = new int[n];
	for(k=1,q=p,pc=c;k<=n;)*q++=*pc++=k++;k=1;pc=c;
	do{t=*(p+k);*(p+k)=*(q=p+((k&1)?*pc:0));*q=t;
	
	//TODO
	tw = r[0] + 2.0 * sqs[r[0]][r[p[0]+1]];
	for(int i = 0; i < n-1; i++){
		tw += 2.0 * sqs[ r[p[i]+1] ][ r[p[i+1]+1] ];
	}
	tw += r[1] + 2.0 * sqs[ r[1] ][ r[p[n-1]+1] ];
	if( tw <= w ){
		//cout << tw << endl;
		delete [] c;
		return true;
	}
	
	k=1;pc = c;while(*pc==0)*pc++=k++;(*pc)--;}while(k<n);

	delete [] c;
	return false;
}
double CalcCirclesLength(vector<int> &r){
	double ret;
	ret = r[0];
	cout << r[0] << ' ';
	for(unsigned int i = 0; i < r.size() - 1; ++i){
		ret += 2.0 * sqs[ r[i] ][ r[i+1] ];
		cout << sqs[ r[i] ][ r[i+1] ] << ' ';
	}
	cout << r[r.size() - 1] << endl;
	ret += r[r.size() - 1];
	return ret;
}
int main(void){
	for(int i = 1; i < sizeof(sqs)/sizeof(*sqs); ++i){
		for(int j = 1; j < sizeof(*sqs)/sizeof(**sqs); ++j){
			sqs[i][j] = sqrt((double)i * j);
		}
	}
	while(true){
		int w;
		double length = 0;
		vector<int> vCandR;
		vector<int> vR;
		
		cin >> w;
		if( cin.eof() ) break;
		while( true ){
			int tmp;
			cin >> tmp;
			vCandR.push_back(tmp);
			if( '\n' == cin.get() ) break;
		}

		vR.push_back(vCandR[0]);
		vCandR.erase( vCandR.begin()+0 );
		while( vCandR.size() > 0 ){

			for(unsigned int i = 0; i < vCandR.size(); ++i){
				double minlen = 5000;
				int minind = 0;
				int minins = 0;
				double l;

				for(unsigned j = 0; j <= vR.size(); j++){
					vR.insert(vR.begin()+j,vCandR[i]);
					l = CalcCirclesLength( vR );
					if( l < minlen ){
						minlen = l; minind = i; minins = j;
					}
					vR.erase(vR.begin()+j);
				}
			}
			vR.insert( vR.begin() + minins, vCandR[minind] );
			/*for(unsigned int i = 0; i < vR.size(); ++i){
				cout << vR[i] << ' ';
			}
			cout << endl;*/
			vCandR.erase( vCandR.begin() + minind );
		}
		cout << CalcCirclesLength( vR ) << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:130:49: error: 'minins' was not declared in this scope
  130 |                         vR.insert( vR.begin() + minins, vCandR[minind] );
      |                                                 ^~~~~~
a.cc:130:64: error: 'minind' was not declared in this scope
  130 |                         vR.insert( vR.begin() + minins, vCandR[minind] );
      |                                                                ^~~~~~