Problem:
Problem F:
Connect Line Segments
Your dear son Arnie is addicted to a puzzle named
Connect Line Segments
.
In this puzzle, you are given several line segments placed on a two-dimensional area. You are allowed to add
some new line segments each connecting the end points of two existing line segments. The objective is to form a
single polyline, by connecting all given line segments, as short as possible. The resulting polyline is allowed to
intersect itself.
Arnie has solved many instances by his own way, but he is wondering if his solutions are the best one. He knows
you are a good programmer, so he asked you to write a computer program with which he can verify his solutions.
Please respond to your dear Arnie’s request.
Input
The input consists of multiple test cases.
Each test case begins with a line containing a single integer
n
(2 ≤
n
≤ 14), which is the number of the initial
line segments. The following
n
lines are the description of the line segments. The
i
-th line consists of four real
numbers:
x
i
,1
,
y
i
,1
,
x
i
,2
, and
y
i
,2
(-100 ≤
x
i
,1
,
y
i
,1
,
x
i
,2
,
y
i
,2
≤ 100). (
x
i
,1
,
y
i
,1
) and (
x
i
,2
,
y
i
,2
) are the coordinates of
the end points of the
i
-th line segment.
The end of the input is indicated by a line with single “0”.
Output
For each test case, output the case number followed by the minimum length in a line.
The output value should be printed with five digits after the decimal point, and should not contain an error greater
than 0.00001.
Sample Input
4
0 1 0 9
10 1 10 9
1 0 9 0
1 10 9 10
2
1.2 3.4 5.6 7.8
5.6 3.4 1.2 7.8
0
Output for the Sample Input
Case 1: 36.24264
Case 2: 16.84508

Submitted solutions:

code_snippet: #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<complex>
#include<vector>
#include<algorithm>
using namespace std;
const int MAXN=1<<14;
const double inf=1.0e20;
typedef complex<double> point;
vector<int> s[MAXN],t[MAXN];
point A, B;
double dp[MAXN][30];
double dist[14][2][14][2];

struct Line : public vector<point> {
    Line() {}
    Line(const point& a, const point& b) { push_back(a); push_back(b); }
}line[14];

int main(){
    int n, cs=1;
    double x1, y1, x2, y2;
    for(int i=0; i<MAXN; i++){
        for(int j=0; j<14; j++){
            if(i&(1<<j)) s[i].push_back(j);
            else t[i].push_back(j);
        }
    }
    while(cin>>n&&n){
        double sum=0;
        for(int i=0; i<n; i++){
            scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
            A=point(x1,y1); B=point(x2,y2);
            line[i]=Line(A,B);
            sum+=abs(A-B);
        }
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                for(int k=0; k<2; k++){
                    for(int u=0; u<2; u++){
                         dist[i][k][j][u]=abs(line[i][k]-line[j][u]);
                    }
                }
            }
        }
        for(int i=1; i<(1<<n); i++){
            if(__builtin_popcount(i)>1){
                for(int j=0; j<(n<<1); j++)
                    dp[i][j]=inf;
            }
        }
        for(int i=1; i<(1<<n); i++){
            int sz=t[i].size();
            int sz2=s[i].size();
            for(int j=0; j<sz; j++){
                int v=t[i][j];
                if(v>n) break;
                int idx=1<<v|i;
                for(int m=0; m<sz2; m++){
                    int w=s[i][m];
                    if(w>n) break;
                    for(int k=0; k<2; k++){
                        for(int u=0; u<2; u++){
                            dp[idx][v<<1|k]=min(dp[idx][v<<1|k],dp[i][w<<1|u]+dist[v][!k][w][u]);
                        }
                    }
                }
            }
        }
        int mask=(1<<n)-1;
        double ans=inf;
        for(int i=0; i<(n<<1); i++){
            ans=min(ans,dp[mask][i]);
        }
        printf("Case %d: %.5f\n",cs++,ans+sum);
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 9836
final_rank: 2

code_snippet: #include <bits/stdc++.h>


using namespace std;
//make -f ../makefile SRC=
/*
dp on mask
*/


//------------------------------------------------------------------------------
bool DEBUG = false;
const double INF = 1e18;

const int MAX_N = 14;
const int F = 2;

static double X[MAX_N][F];
static double Y[MAX_N][F];
static double S[1<<MAX_N][MAX_N][F];
//------------------------------------------------------------------------------
double dist2(double x1, double y1, double x2, double y2)
{
    return (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
}

double dist(double x1, double y1, double x2, double y2)
{
    return sqrt( double(dist2(x1,y1,x2,y2)) );
}

double dist(int N, int i, int f1, int j, int f2)
{
    return dist(X[i][f1], Y[i][f1], X[j][f2], Y[j][f2]);
}

double dp(int N, int mask, int i, int f)
{
    if (S[mask][i][f] != -1) return S[mask][i][f];
    double& res = S[mask][i][f];
    if (__builtin_popcount(mask) == 1) { res = 0; return res; }

    res = INF;
    int mask1 = (mask^(1<<i));
    for (int i1=0; i1<N; ++i1)
    {
        if (!(mask1 & (1<<i1))) continue;
        for (int f1=0; f1<F; ++f1)
        {
            double d0 = dist(N, i, !f, i1, f1);
            res = min(res, d0 + dp(N, mask1, i1, f1));
        }
    }
    return res;
}

//------------------------------------------------------------------------------
double solve(int N)
{
    if (DEBUG)
    {
        for (int i=0; i<N; ++i)
        {
            for (int f=0; f<F; ++f) printf("%lf %lf ", X[i][f], Y[i][f]);
            printf("\n");
        }
        printf("%lf\n", dist(N, 0, 0, 1, 0));
        printf("%lf\n", dist(N, 0, 0, 1, 1));
        printf("%lf\n", dist(N, 0, 1, 1, 0));
        printf("%lf\n", dist(N, 0, 1, 1, 1));
    }
    //--------------------------------------------------------------------------
    // base cases:
    //--------------------------------------------------------------------------
    // init:
    for (int m=0; m<(1<<N); ++m)
        for (int i=0; i<N; ++i)
            for (int f=0; f<F; ++f)
                S[m][i][f] = -1;
    //--------------------------------------------------------------------------
    // compute:
    double res = INF;
    int mask = (1<<N)-1;
    
    //--------------------------------------------------------------------------
    for (int i=0; i<N; ++i) for (int f=0; f<F; ++f) res = min(res, dp(N, mask, i, f));

    if (DEBUG)
    {
        for (int m=0; m<(1<<N); ++m)
            for (int i=0; i<N; ++i)
                for (int f=0; f<F; ++f)
                    if (S[m][i][f] != -1)
                        printf("m=%d, i=%d, f=%d: %lf\n", m, i, f, S[m][i][f]);
    }
    //--------------------------------------------------------------------------
    // report:
    //printf("%lf\n", res);
    for (int i=0; i<N; ++i) res += dist(N, i, 0, i, 1);
    return res;
}

//------------------------------------------------------------------------------
void test()
{

}

//------------------------------------------------------------------------------
int main()
{
    //test(); return 0;
    //DEBUG = true;
    //--------------------------------------------------------------------------
    int N, t, num;
    t = 1;
    while (true)
    {
        num = scanf("%d ", &N);
        if (N == 0) break;
        for (int i=0; i<N; ++i)
            for (int f=0; f<F; ++f)
                num = scanf("%lf %lf ", &X[i][f], &Y[i][f]);
        double res = solve(N);
        printf("Case %d: %lf\n", t, res);
        t++;
    }
    //--------------------------------------------------------------------------
    return 0;
}
//------------------------------------------------------------------------------
accuracy: 1
time_ms: 160
memory_kb: 7100
final_rank: 5

code_snippet: #include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>
#include <stack>
#include <numeric>
#include <climits>
#include <cfloat>

struct BitSet {
	int to_int;
	BitSet operator+(const int value) const {
		return BitSet{ to_int | (1 << value) };
	}
	bool is_contains(const int value) const {
		return (to_int & (1 << value)) != 0;
	}
};
struct Point {
	double x, y;
	double distance(const Point& that) const {
		return std::sqrt((x - that.x) * (x - that.x) + (y - that.y) * (y - that.y));
	}
};
double solve(const BitSet set, const int end_a, const int end_b, const std::vector<std::vector<Point>>& lines, std::vector<std::vector<std::vector<double>>>& memo) {
	auto& res = memo[set.to_int][std::max(end_a, end_b)][std::min(end_a, end_b)];
	if (res >= 0) return res;
	else {
		res = DBL_MAX;
		for (auto i = 0; i < lines.size(); ++i) if (!set.is_contains(i)){
			auto temp = std::min({
				solve(set + i, end_a, i * 2 + 1, lines, memo) + lines[i][0].distance(lines[end_b / 2][end_b % 2]),
				solve(set + i, end_a, i * 2, lines, memo) + lines[i][1].distance(lines[end_b / 2][end_b % 2]),
				solve(set + i, end_b, i * 2 + 1, lines, memo) + lines[i][0].distance(lines[end_a / 2][end_a % 2]),
				solve(set + i, end_b, i * 2, lines, memo) + lines[i][1].distance(lines[end_a / 2][end_a % 2])
				});
			if (temp < res) res = temp;
		}
		if (res == DBL_MAX) return res = 0;
		return res;
	}
}
int main() {
	int count = 1;
	std::cout << std::setprecision(9) << std::fixed;
	while (true) {
		int n; std::cin >> n; if (n == 0) return 0;
		std::vector<std::vector<Point>> lines(n, std::vector<Point>(2)); for (auto& line : lines) for (auto& point : line) std::cin >> point.x >> point.y;
		std::vector<std::vector<std::vector<double>>> memo(1 << n, std::vector<std::vector<double>>(2 * n));
		for (auto i = 0; i < memo.size(); ++i) for (auto j = 0; j < memo[i].size(); ++j) memo[i][j] = std::vector<double>(j, -1);
		double line_length = 0;
		for (const auto& line : lines) line_length += line[0].distance(line[1]);
		std::cout << "Case " << count++ << ": " << solve(BitSet{ 1 }, 0, 1, lines, memo) + line_length << std::endl;
	}
}
accuracy: 1
time_ms: 1920
memory_kb: 68108
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

/* 基本要素 */
typedef complex<double> Point;
typedef pair<Point, Point> Line;
typedef vector<Point> VP;
const double INF = 1e9;

Point READP(){
    double x,y;
    scanf(" %lf %lf", &x, &y);
    return {x,y};
}

VP READ(){
    return VP({READP(), READP()});
}

const int N = 14;
double dp[1<<N][N][2];

int main(){
    int CASE = 1;
    int n;
    while(scanf(" %d", &n),n){
        vector<VP> s(n);
        rep(i,n) s[i] = READ();

        rep(i,1<<N)rep(j,N)rep(k,2) dp[i][j][k] = INF;
        rep(i,n)rep(j,2) dp[1<<i][i][j] = 0;

        rep(mask,1<<n)rep(i,n){
            if(!(mask>>i&1)) continue;
            rep(ii,2){
                double D = dp[mask][i][ii];
                Point start = s[i][ii];

                // next
                rep(j,n){
                    if(mask>>j&1) continue;
                    rep(jj,2){
                        Point goal = s[j][jj];
                        int nmask = mask|(1<<j);
                        dp[nmask][j][!jj] = min(dp[nmask][j][!jj], D+abs(start-goal));
                    }
                }
            }
        }

        double ans = INF;
        rep(i,n)rep(j,2) ans = min(ans, dp[(1<<n)-1][i][j]);

        rep(i,n) ans += abs(s[i][0]-s[i][1]);
        printf("Case %d: %.5f\n", CASE, ans);
        ++CASE;
    }
    return 0;
}
accuracy: 1
time_ms: 360
memory_kb: 6728
final_rank: 9

code_snippet: #include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
const double INF = 1e12;
typedef complex<double> P;

int main(){
    for(int rep=1; ; rep++){
        int n;
        cin >> n;
        if(n==0) break;

        vector<vector<P> > seg(n, vector<P>(2));
        double sum = 0;
        for(int i=0; i<n; i++){
            for(int j=0; j<2; j++){
                double x,y;
                cin >> x >> y;
                seg[i][j] = P(x, y);
            }
            sum += abs(seg[i][0] -seg[i][1]);
        }

        vector<vector<vector<double> > > dp(1<<n, vector<vector<double> >(n, vector<double>(2, INF)));
        for(int i=0; i<n; i++){
            dp[1<<i][i][0] = dp[1<<i][i][1] = 0;
        }
        for(int i=0; i<(1<<n); i++){
            for(int j=0; j<n; j++){
                if((i & 1<<j) == 0) continue;
                for(int k=0; k<n; k++){
                    if((i & 1<<k) != 0) continue;
                    for(int s=0; s<2; s++){
                        for(int t=0; t<2; t++){
                            dp[i | 1<<k][k][t] = min(dp[i | 1<<k][k][t], dp[i][j][s] + abs(seg[j][1-s] -seg[k][t]));
                        }
                    }
                }
            }
        }

        double ans = INF;
        for(int i=0; i<n; i++){
            for(int j=0; j<2; j++){
                ans = min(ans, dp[(1<<n)-1][i][j]);
            }
        }
        ans += sum;
        cout << fixed << setprecision(5);
        cout << "Case " << rep << ": " << ans << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 420
memory_kb: 16176
final_rank: 15

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


enum Type{
	First,
	Second,
};


struct Point{
	double x,y;
};

struct Line{
	Point p[2];
	double length;
};


int N,case_num = 1;
int POW[15];
Line line[15];
double min_cost[16384][14][2];

double calc_dist(Point a,Point b){
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

void func(){

	for(int i = 0; i < N; i++){
		scanf("%lf %lf %lf %lf",&line[i].p[0].x,&line[i].p[0].y,&line[i].p[1].x,&line[i].p[1].y);
		line[i].length = calc_dist(line[i].p[0],line[i].p[1]);
	}

	double dist_first,dist_second,ans = 9999999.0;


	for(int start = 0; start < N; start++){

		for(int state = 0; state < POW[N]; state++){
			for(int current = 0; current < N; current++){
				min_cost[state][current][First] = 9999999.0;
				min_cost[state][current][Second] = 9999999.0;
			}
		}

		for(int next = 0; next < N; next++){
			if(next == start)continue;

			dist_first = calc_dist(line[start].p[0],line[next].p[0]);
			dist_second = calc_dist(line[start].p[1],line[next].p[0]);

			min_cost[POW[next]+POW[start]][next][First] = min(dist_first,dist_second)+line[start].length;

			dist_first = calc_dist(line[start].p[0],line[next].p[1]);
			dist_second = calc_dist(line[start].p[1],line[next].p[1]);

			min_cost[POW[next]+POW[start]][next][Second] = min(dist_first,dist_second)+line[start].length;
		}

		for(int state = 2; state < POW[N]; state++){
			for(int last_line = 0; last_line < N; last_line++){
				if(min_cost[state][last_line][First] == 9999999.0)continue;

				for(int next_line = 0; next_line < N; next_line++){
					if(state & (1 << next_line)){
						//Do nothing
					}else{

						dist_first = calc_dist(line[next_line].p[0],line[last_line].p[0]);
						dist_second = calc_dist(line[next_line].p[0],line[last_line].p[1]);

						min_cost[state+POW[next_line]][next_line][First] = min(min_cost[state+POW[next_line]][next_line][First],
								min(min_cost[state][last_line][First]+dist_second,min_cost[state][last_line][Second]+dist_first)+line[last_line].length);


						dist_first = calc_dist(line[next_line].p[1],line[last_line].p[0]);
						dist_second = calc_dist(line[next_line].p[1],line[last_line].p[1]);

						min_cost[state+POW[next_line]][next_line][Second] = min(min_cost[state+POW[next_line]][next_line][Second],
								min(min_cost[state][last_line][First]+dist_second,min_cost[state][last_line][Second]+dist_first)+line[last_line].length);

					}
				}
			}
		}

		for(int last_line = 0; last_line < N; last_line++){
			if(last_line == start)continue;

			ans = min(ans,min(min_cost[POW[N]-1][last_line][First],min_cost[POW[N]-1][last_line][Second])+line[last_line].length);
		}
	}

	printf("Case %d: %.5lf\n",case_num,ans);
	case_num++;
}

int main(){

	for(int i = 0; i < 15; i++)POW[i] = pow(2,i);

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}
accuracy: 1
time_ms: 610
memory_kb: 6940
final_rank: 14

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

using ld= long double;

ld get_dis(const pair<ld,ld>&l,const pair<ld, ld>&r) {
	return sqrt((l.first-r.first)*(l.first-r.first)+(l.second-r.second)*(l.second-r.second));

}

ld dfs(vector<vector<vector<ld>>>&memo,const vector<vector<pair<ld, ld>>>&lines, const int now, const int is_a, bitset<14>&bs) {
	if (memo[now][bs.to_ulong()][is_a] > -1) {
		return memo[now][bs.to_ulong()][is_a];
	}
	if (bs.count() == memo.size()) {
		memo[now][bs.to_ulong()][is_a]=0;
	}
	else {
		ld ans=1e9;
		for (int next = 0; next < lines.size(); ++next) {
			if(bs[next])continue;
			else {
				for (int next_is_a = 0; next_is_a < 2; ++next_is_a) {
					ld plus=get_dis(lines[now][is_a],lines[next][next_is_a]);
					bs[next]=true;
					plus+=dfs(memo,lines,next,!next_is_a,bs);
					bs[next]=false;
					ans=min(ans,plus);
				}
			}
		}

		memo[now][bs.to_ulong()][is_a]=ans;
	}

	return memo[now][bs.to_ulong()][is_a];
}

int main() {
	int case_id=0;
	while (true) {
		case_id++;
		int N;cin>>N;
		if(!N)break;
		vector<vector<pair<ld, ld>>>lines(N);
		for (int i = 0; i < N; ++i) {
			ld x1,y1,x2,y2;cin>>x1>>y1>>x2>>y2;
			lines[i] = vector<pair<ld,ld>>{ make_pair(x1,y1),make_pair(x2,y2) };
		}
		bitset<14>used;
		vector<vector<vector<ld>>>memo(N,vector<vector<ld>>(1<<14,vector<ld>(2,-1e9)));

		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < 2; ++j) {
				memo[i][0][j]=0;

			}
		}
		ld ans=1e9;
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < 2; ++j) {
				used[i]=true;
				ans=min(ans,dfs(memo,lines,i,j,used));
				used[i]=false;
			}
		}
		for (auto line : lines) {
			ans+=get_dis(line[0],line[1]);
		}
		cout<<setprecision(10)<<fixed;
		cout<<"Case "<<case_id<<": "<<ans<<endl;
	}
	
	return 0;
}
accuracy: 1
time_ms: 1230
memory_kb: 20084
final_rank: 19

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct Point {
  double x, y;
  Point(double x = 0, double y = 0):x(x), y(y){}
};

int n;
Point seg[2][14];
double dp[2][14][1<<14];

double sq(double x) {
  return x*x;
}

double dist(Point p, Point q) {
  return sqrt(sq(p.x-q.x)+sq(p.y-q.y));
}

double solve(int idx, int ep, int bit) {
  if(bit == (1<<n)-1) return 0.0;
  double &res = dp[ep][idx][bit];
  if(res != -1.0) return res;
  res = 1e9;
  rep(i, n) {
    if((bit>>i)&1) continue;
    rep(j, 2) res = min(res, solve(i, j, bit|1<<i) + dist(seg[ep][idx], seg[!j][i]));
  }
  return res;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  for(int t = 1; cin >> n, n; t++) {
    double sum = 0.0;
    rep(i, n) {
      rep(j, 2) cin >> seg[j][i].x >> seg[j][i].y;
      sum += dist(seg[0][i], seg[1][i]);
    }

    double ans = 1e9;
    rep(i, 2) rep(j, 14) rep(k, 1<<14) dp[i][j][k] = -1.0;
    rep(i, n) {
      ans = min(ans, solve(i, 0, 1<<i), solve(i, 1, 1<<i));
    }
    cout << "Case " << t << ": " << ans+sum << endl;
  }

  return 0;
}
accuracy: 1
time_ms: 250
memory_kb: 6836
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<double,double> P;
double D(P a, P b){return sqrt((a.F-b.F)*(a.F-b.F)+(a.S-b.S)*(a.S-b.S));}
 
int main() {
  int n,tt=1;
  while(cin>>n&&n) {
    P a[n][2];
    for(int i=0; i<n; i++) {
      for(int j=0; j<2; j++) cin >> a[i][j].F >> a[i][j].S;
    }
    double dp[1<<n][n][2];
    for(int t=0;t<(1<<n);t++)for(int i=0;i<n;i++)for(int j=0;j<2;j++)dp[t][i][j]=1<<29;
    for(int i=0; i<n; i++) {
      for(int j=0; j<2; j++) dp[1<<i][i][j]=D(a[i][0],a[i][1]);
    }
    for(int t=0; t<(1<<n); t++) {
      for(int i=0; i<n; i++) {
        if(!(t&(1<<i))) continue;
        for(int j=0; j<2; j++) {
          for(int k=0; k<n; k++) {
            if(t&(1<<k)) continue;
            for(int l=0; l<2; l++) {
              dp[t|(1<<k)][k][l^1]=min(dp[t|(1<<k)][k][l^1],dp[t][i][j]+D(a[i][j],a[k][l])+D(a[k][0],a[k][1]));
            }
          }
        }
      }
    }
    double ans=1<<29;
    for(int i=0; i<n; i++)for(int j=0; j<2; j++) ans=min(ans,dp[(1<<n)-1][i][j]);
    cout<<"Case "<<tt++<<": ";
    printf("%.10f\n",ans);
  }
  return 0;
}
accuracy: 1
time_ms: 200
memory_kb: 6756
final_rank: 6

code_snippet: #include<bits/stdc++.h>
#define INF (1e9)
#define MAX_N 14
using namespace std;
typedef complex<double> P;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
int n;
double x,y;
double dp[(1<<MAX_N)][MAX_N*2];
vector<P> v;

int main(){
  int T=1;
  while(1){
    cin>>n;
    if(!n)break;
    double ans=0;
    for(int i=0;i<n;i++){
      cin>>x>>y;
      v.push_back(P(x,y));
      cin>>x>>y;
      v.push_back(P(x,y));
      ans+=abs(v[v.size()-1]-v[v.size()-2]);
    }
    Fill(dp,INF);
    for(int i=0;i<n*2;i++)
      dp[(1<<(i/2))][i]=0;
    for(int i=0;i<(1<<n);i++){
      for(int j=0;j<n*2;j++){
	if(dp[i][j]==INF)continue;
	int p1=j;
	for(int l=0;l<n;l++){
	  if(i&(1<<l))continue;
	  int p3=l*2,p4=l*2+1;
	  int next=p4;
	  dp[i|(1<<l)][next]=min(dp[i|(1<<l)][next],dp[i][j]+abs(v[p1]-v[p3]));
	  next=p3;
	  dp[i|(1<<l)][next]=min(dp[i|(1<<l)][next],dp[i][j]+abs(v[p1]-v[p4]));
	}
      }
    }
    double minl=INF;
    for(int i=0;i<n*2;i++)
      minl=min(minl,dp[(1<<n)-1][i]);
    ans+=minl;
    cout<<"Case "<<T<<": ";
    printf("%.5f\n",ans);
    T++;
    v.clear();
  }
  return 0;
}
accuracy: 1
time_ms: 370
memory_kb: 6836
final_rank: 11

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct Point{
  double x,y;
  Point(){}
  Point(double x,double y):x(x),y(y){}
  Point operator-(Point p){
    return Point(x-p.x,y-p.y);
  }
};

double norm(Point a){
  return a.x*a.x+a.y*a.y;
}

double abs(Point a){
  return sqrt(norm(a));
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  int n,t=1;
  while(cin>>n,n){
    Point p[2][n];
    for(int i=0;i<n;i++) cin>>p[0][i].x>>p[0][i].y>>p[1][i].x>>p[1][i].y;
    double dp[2][n][1<<n],inf=1<<30;
    //cout<<inf<<endl;

    for(int x=0;x<2;x++)
      for(int i=0;i<n;i++) 
	for(int j=0;j<(1<<n);j++)
	  dp[x][i][j]=inf;
    
    for(int i=0;i<n;i++) dp[0][i][1<<i]=dp[1][i][1<<i]=0;
    
    for(int i=0;i<(1<<n);i++){
      for(int j=0;j<n;j++){
	if(!((i>>j)&1)) continue;
	for(int k=0;k<n;k++){
	  if((i>>k)&1) continue;
	  for(int x=0;x<2;x++)
	    for(int y=0;y<2;y++)
	      dp[x][k][i+(1<<k)]=
		min(dp[x][k][i+(1<<k)],dp[y][j][i]+abs(p[!x][k]-p[y][j]));
	}
      }
    }
    
    double ans=inf;
    for(int i=0;i<n;i++) ans=min(ans,dp[0][i][(1<<n)-1]);
    for(int i=0;i<n;i++) ans=min(ans,dp[1][i][(1<<n)-1]);
    
    for(int i=0;i<n;i++) ans+=abs(p[0][i]-p[1][i]);
    
    printf("Case %lld: %.5f\n",t,ans);
    t++;
  }
  return 0;
}
accuracy: 1
time_ms: 120
memory_kb: 6804
final_rank: 4

code_snippet: #include <bits/stdc++.h>
#define N 14
using namespace std;
int n;
typedef pair<double,double> P;
typedef pair<P,P> PP;

double X[N],Y[N],X2[N],Y2[N];

double dis(double x,double y,double x2,double y2){
  return sqrt((x-x2)*(x-x2)+(y-y2)*(y-y2));
}

map<P,double> mem[1<<N];

double dfs(double x,double y,int bit){
  if(bit==(1<<n)-1) return 0; 
 
  P sta = P(x,y);
  if(mem[bit].count(sta)) return mem[bit][sta];
  
  double res=1e9;
  for(int i=0;i<n;i++){
    if(bit&(1<<i))continue;
    int nbit = bit|1<<i;
    double a = dis(x,y,X[i],Y[i]) + dfs(X2[i],Y2[i],nbit);
    double b = dis(x,y,X2[i],Y2[i]) + dfs(X[i],Y[i],nbit);
    res = min(res,min(a,b));
  }
  return mem[bit][sta]=res;
}


int main(){
  int Case=0;
  while(1){
  cin>>n;
  if(n==0) break;
  double sum =0;
  for(int i=0;i<n;i++) cin>>X[i]>>Y[i]>>X2[i]>>Y2[i],sum+=dis(X[i],Y[i],X2[i],Y2[i]);
  for(int i=0;i<(1<<N);i++) mem[i].clear();
  
  double ans = 1e9;
  for(int i=0;i<n;i++) 
    ans = min(ans, min(dfs(X2[i],Y2[i],1<<i),dfs(X[i],Y[i],1<<i)));
  printf("Case %d: %.10f\n",++Case,ans+sum);
  }  
  return 0;
}
accuracy: 1
time_ms: 1160
memory_kb: 18196
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<double,double> P;
double D(P a, P b){return sqrt((a.F-b.F)*(a.F-b.F)+(a.S-b.S)*(a.S-b.S));}

int main() {
  int n,tt=1;
  while(cin >> n && n) {
    P a[n][2];
    for(int i=0; i<n; i++) {
      for(int j=0; j<2; j++) cin >> a[i][j].F >> a[i][j].S;
    }
    double dp[1<<n][n][2];
    for(int t=0;t<(1<<n);t++)for(int i=0;i<n;i++)for(int j=0;j<2;j++)dp[t][i][j]=1<<29;
    for(int i=0; i<n; i++) {
      for(int j=0; j<2; j++) dp[1<<i][i][j]=D(a[i][0],a[i][1]);
    }
    for(int t=0; t<(1<<n); t++) {
      for(int i=0; i<n; i++) {
        if(!(t&(1<<i))) continue;
        for(int j=0; j<2; j++) {
          for(int k=0; k<n; k++) {
            if(t&(1<<k)) continue;
            for(int l=0; l<2; l++) {
              dp[t|(1<<k)][k][l^1]=min(dp[t|(1<<k)][k][l^1],dp[t][i][j]+D(a[i][j],a[k][l])+D(a[k][0],a[k][1]));
            }
          }
        }
      }
    }
    double ans=1<<29;
    for(int i=0; i<n; i++)for(int j=0; j<2; j++) ans=min(ans,dp[(1<<n)-1][i][j]);
    cout << "Case " << tt++ << ": ";
    printf("%.10f\n",ans);
  }
  return 0;
}
accuracy: 1
time_ms: 200
memory_kb: 6764
final_rank: 7

code_snippet: #include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int n; long double sx[16], sy[16], tx[16], ty[16], dp[1 << 15][15][2];
long double dst(long double ax, long double ay, long double bx, long double by) {
	return sqrt((ax - bx)*(ax - bx) + (ay - by)*(ay - by));
}
int main() {
	int d = 0;
	while (true) {
		cin >> n; if (n == 0)break; long double ret = 0; d++;
		for (int i = 0; i < n; i++) {
			cin >> sx[i] >> sy[i] >> tx[i] >> ty[i];
			ret += dst(sx[i], sy[i], tx[i], ty[i]);
		}
		for (int i = 0; i < (1 << n); i++) {
			for (int j = 0; j < n; j++) { dp[i][j][0] = 1e10; dp[i][j][1] = 1e10; }
		}
		for (int i = 0; i < n; i++) { dp[(1 << i)][i][0] = 0; dp[(1 << i)][i][1] = 0; }
		for (int i = 0; i < (1 << n); i++) {
			for (int j = 0; j < n; j++) {
				if (dp[i][j][0] <= 1e9) {
					for (int k = 0; k < n; k++) {
						if ((i&(1 << k)) != 0)continue;
						dp[i + (1 << k)][k][0] = min(dp[i + (1 << k)][k][0], dp[i][j][0] + dst(tx[j], ty[j], sx[k], sy[k]));
						dp[i + (1 << k)][k][1] = min(dp[i + (1 << k)][k][1], dp[i][j][0] + dst(tx[j], ty[j], tx[k], ty[k]));
					}
				}
				if (dp[i][j][1] <= 1e9) {
					for (int k = 0; k < n; k++) {
						if ((i&(1 << k)) != 0)continue;
						dp[i + (1 << k)][k][0] = min(dp[i + (1 << k)][k][0], dp[i][j][1] + dst(sx[j], sy[j], sx[k], sy[k]));
						dp[i + (1 << k)][k][1] = min(dp[i + (1 << k)][k][1], dp[i][j][1] + dst(sx[j], sy[j], tx[k], ty[k]));
					}
				}
			}
		}
		long double minx = 1e10;
		for (int i = 0; i < n; i++) {
			minx = min(minx, min(dp[(1 << n) - 1][i][0], dp[(1 << n) - 1][i][1]));
		}
		cout << "Case " << d << ": "; printf("%.9Lf\n", minx + ret);
	}
	return 0;
}
accuracy: 1
time_ms: 240
memory_kb: 10760
final_rank: 10

code_snippet: #include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
int n, popcount[16399]; double x[16][2], y[16][2], dist[16][2][16][2], dp[16399][16][2];
int main() {
	for (int i = 0; i < 14; i++) {
		for (int j = 1 << i; j < 2 << i; j++) {
			popcount[j] = popcount[j - (1 << i)] + 1;
		}
	}
	int cnt = 0;
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) cin >> x[i][0] >> y[i][0] >> x[i][1] >> y[i][1];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 2; j++) {
				for (int k = 0; k < n; k++) {
					for (int l = 0; l < 2; l++) {
						dist[i][j][k][l] = hypot(x[i][j] - x[k][l], y[i][j] - y[k][l]);
					}
				}
			}
		}
		for (int i = 0; i < 1 << n; i++) {
			for (int j = 0; j < n; j++) {
				dp[i][j][0] = dp[i][j][1] = 1.0e+10;
			}
		}
		for (int i = 0; i < n; i++) dp[1 << i][i][0] = dp[1 << i][i][1] = 0.0;
		for (int i = 1; i < 1 << n; i++) {
			if (popcount[i] == 1) continue;
			for (int j = 0; j < n; j++) {
				if (!(i & (1 << j))) continue;
				int sub = i - (1 << j);
				for (int k = 0; k < 2; k++) {
					for (int l = 0; l < n; l++) {
						if (!(sub & (1 << l))) continue;
						for (int m = 0; m < 2; m++) {
							dp[i][j][k] = min(dp[i][j][k], dp[sub][l][m] + dist[j][k ^ 1][l][m]);
						}
					}
				}
			}
		}
		double ret = 1.0e+10;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 2; j++) {
				ret = min(ret, dp[(1 << n) - 1][i][j]);
			}
		}
		for (int i = 0; i < n; i++) ret += dist[i][0][i][1];
		printf("Case %d: %.5lf\n", ++cnt, ret);
	}
	return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 7280
final_rank: 1

code_snippet: #include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
int n, popcount[16399]; double x[16][2], y[16][2], dp[16399][16][2];
int main() {
	for (int i = 0; i < 14; i++) {
		for (int j = 1 << i; j < 2 << i; j++) {
			popcount[j] = popcount[j - (1 << i)] + 1;
		}
	}
	int cnt = 0;
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) cin >> x[i][0] >> y[i][0] >> x[i][1] >> y[i][1];
		for (int i = 0; i < 1 << n; i++) {
			for (int j = 0; j < n; j++) {
				dp[i][j][0] = dp[i][j][1] = 1.0e+10;
			}
		}
		for (int i = 0; i < n; i++) dp[1 << i][i][0] = dp[1 << i][i][1] = 0.0;
		for (int i = 1; i < 1 << n; i++) {
			if (popcount[i] == 1) continue;
			for (int j = 0; j < n; j++) {
				if (!(i & (1 << j))) continue;
				int sub = i - (1 << j);
				for (int k = 0; k < 2; k++) {
					for (int l = 0; l < n; l++) {
						if (!(sub & (1 << l))) continue;
						for (int m = 0; m < 2; m++) {
							double dist = hypot(x[j][k ^ 1] - x[l][m], y[j][k ^ 1] - y[l][m]);
							dp[i][j][k] = min(dp[i][j][k], dp[sub][l][m] + dist);
						}
					}
				}
			}
		}
		double ret = 1.0e+10;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 2; j++) {
				ret = min(ret, dp[(1 << n) - 1][i][j]);
			}
		}
		for (int i = 0; i < n; i++) {
			ret += hypot(x[i][0] - x[i][1], y[i][0] - y[i][1]);
		}
		printf("Case %d: %.5lf\n", ++cnt, ret);
	}
	return 0;
}
accuracy: 1
time_ms: 360
memory_kb: 7352
final_rank: 12

code_snippet: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
 
using namespace std;
 
#define MAX 15
#define INF 1e9
 
struct Point{
    double x,y;
    Point(){}
    Point(double x,double y) : x(x), y(y) {}
};
 
struct Segment{
    Point s,t;
    Segment(){}
    Segment(Point s,Point t) : s(s), t(t) {}
};
 
int N;
double dp[1<<MAX][MAX][2];
Segment Seg[MAX];
double d[MAX];
 
double getDistance(Point &p1,Point &p2){
    return sqrt(pow(p1.x-p2.x,2)+pow(p1.y-p2.y,2));
}
 
double solve(int S,int now,bool st){
    if((1<<N)-1 == S){
	if(st){
	    return dp[S][now][st] = d[now];
	}else{
	    return dp[S][now][st] = d[now];
	}
    }
    if(dp[S][now][st] != INF){
	return dp[S][now][st];
    }
    double res = INF;
    for(int i = 0 ; i < N ; i++){
	if(S >> i & 1) continue;
	if(st){
	    res = min(res,solve(S|(1<<i),i,true) + d[now] + getDistance(Seg[now].t,Seg[i].s));
	    res = min(res,solve(S|(1<<i),i,false) + d[now] + getDistance(Seg[now].t,Seg[i].t));     
	}else{
	    res = min(res,solve(S|(1<<i),i,true) + d[now] + getDistance(Seg[now].s,Seg[i].s));
	    res = min(res,solve(S|(1<<i),i,false) + d[now] + getDistance(Seg[now].s,Seg[i].t));   
	}
    }
    return dp[S][now][st] = res;
}
 
int main(){
    int Tc = 1;
    while(cin >> N, N){
	for(int i = 0 ; i < N ; i++){
	    cin >> Seg[i].s.x >> Seg[i].s.y >> Seg[i].t.x >> Seg[i].t.y;
	    d[i] = getDistance(Seg[i].s,Seg[i].t);
	}
	for(int i = 0 ; i < (1<<MAX) ; i++){
	    for(int j = 0 ; j < MAX ; j++){
		for(int k = 0 ; k < 2 ; k++){
		    dp[i][j][k] = INF;
		}
	    }
	}
	double res = INF;
	for(int i = 0 ; i < N ; i++){
	    res = min(res,solve(1<<i,i,true));
	    res = min(res,solve(1<<i,i,false));
	}
	printf("Case %d: %.5f\n",Tc++,res);
    }
    return 0;
}
accuracy: 1
time_ms: 270
memory_kb: 10828
final_rank: 13

code_snippet: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 14;
const int MAXBITS = 1 << MAX_N;
const double DINF = 1e70;

/* typedef */

/* global variables */

int n;
double xs[MAX_N][2], ys[MAX_N][2], ds[MAX_N];
double dp[MAXBITS][MAX_N][2];

/* subroutines */

/* main */

int main() {
  for (int cn = 1;; cn++) {
    cin >> n;
    if (n == 0) break;

    for (int i = 0; i < n; i++) {
      cin >> xs[i][0] >> ys[i][0] >> xs[i][1] >> ys[i][1];
      double dx = xs[i][1] - xs[i][0];
      double dy = ys[i][1] - ys[i][0];
      ds[i] = sqrt(dx * dx + dy * dy);
    }

    for (int b = 0; b < MAXBITS; b++)
      for (int i = 0; i < n; i++)
	for (int k = 0; k < 2; k++) dp[b][i][k] = DINF;

    for (int i = 0; i < n; i++)
	for (int k = 0; k < 2; k++) dp[1 << i][i][k] = ds[i];
    
    for (int bits0 = 1; bits0 < MAXBITS; bits0++) {
      for (int i0 = 0; i0 < n; i0++) {
	int bi0 = 1 << i0;
	if (! (bits0 & bi0)) continue;

	for (int k0 = 0; k0 < 2; k0++) {
	  double dp0 = dp[bits0][i0][k0];
	  double x0 =xs[i0][k0], y0 = ys[i0][k0];

	  for (int i1 = 0; i1 < n; i1++) {
	    int bi1 = 1 << i1;
	    if (bits0 & bi1) continue;
	    int bits1 = bits0 | bi1;
	    
	    for (int k1 = 0; k1 < 2; k1++) {
	      double dx =xs[i1][k1 ^ 1] - x0, dy = ys[i1][k1 ^ 1] - y0;
	      double dp1 = dp0 + sqrt(dx * dx + dy * dy) + ds[i1];
	      if (dp[bits1][i1][k1] > dp1) dp[bits1][i1][k1] = dp1;
	    }
	  }
	}
      }
    }

    double min_d = DINF;
    int allbits = (1 << n) - 1;

    for (int i = 0; i < n; i++)
      for (int k = 0; k < 2; k++)
	if (min_d > dp[allbits][i][k]) min_d = dp[allbits][i][k];

    printf("Case %d: %.5lf\n", cn, min_d);
  }

  return 0;
}
accuracy: 1
time_ms: 800
memory_kb: 4832
final_rank: 16

code_snippet: #include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
double X1[20];
double Y1[20];
double X2[20];
double Y2[20];
double dp[1<<14][14][2];
int main(){
	int T=0;
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)scanf("%lf%lf%lf%lf",X1+i,Y1+i,X2+i,Y2+i);
		for(int i=0;i<(1<<a);i++)for(int j=0;j<a;j++)for(int k=0;k<2;k++)
			dp[i][j][k]=999999999;
		for(int i=0;i<a;i++){
			dp[1<<i][i][0]=dp[1<<i][i][1]=0;
		}
		for(int i=0;i<(1<<a);i++){
			for(int j=0;j<a;j++){
				for(int k=0;k<2;k++){
					if(dp[i][j][k]>99999999)continue;
					for(int l=0;l<a;l++){
						if(i&(1<<l))continue;
						if(!k){
							dp[i+(1<<l)][l][0]=min(dp[i+(1<<l)][l][0],dp[i][j][k]+sqrt((X1[l]-X2[j])*(X1[l]-X2[j])+(Y1[l]-Y2[j])*(Y1[l]-Y2[j])));
							dp[i+(1<<l)][l][1]=min(dp[i+(1<<l)][l][1],dp[i][j][k]+sqrt((X2[l]-X2[j])*(X2[l]-X2[j])+(Y2[l]-Y2[j])*(Y2[l]-Y2[j])));
						}else{
							dp[i+(1<<l)][l][0]=min(dp[i+(1<<l)][l][0],dp[i][j][k]+sqrt((X1[l]-X1[j])*(X1[l]-X1[j])+(Y1[l]-Y1[j])*(Y1[l]-Y1[j])));
							dp[i+(1<<l)][l][1]=min(dp[i+(1<<l)][l][1],dp[i][j][k]+sqrt((X2[l]-X1[j])*(X2[l]-X1[j])+(Y2[l]-Y1[j])*(Y2[l]-Y1[j])));
						}
					}
				}
			}
		}
		double ret=999999999;
		for(int i=0;i<a;i++){
			ret=min(ret,dp[(1<<a)-1][i][0]);
			ret=min(ret,dp[(1<<a)-1][i][1]);
		}
		for(int i=0;i<a;i++)ret+=sqrt((X1[i]-X2[i])*(X1[i]-X2[i])+(Y1[i]-Y2[i])*(Y1[i]-Y2[i]));
		printf("Case %d: %.5f\n",++T,ret);
	}
}
accuracy: 1
time_ms: 180
memory_kb: 4680
final_rank: 3

code_snippet: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



inline double dis(double x1, double y1, double x2, double y2) {
    return sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );
}

const double INF = 1<<29;
double dp[1<<15][20][3];

int main() {
    //freopen( "/Users/macuser/Dropbox/Contest/input.in", "r", stdin );
    double x[2][20], y[2][20];
    int it = 0;
    int n;
    while (cin >> n) {
        if (n == 0) break;
        
        ++it;
        for (int i = 0; i < n; ++i) {
            cin >> x[0][i] >> y[0][i] >> x[1][i] >> y[1][i];
        }
        
        for (int i = 0; i < (1<<15); ++i) for (int j = 0; j < 20; ++j) for (int k = 0; k < 3; ++k) dp[i][j][k] = INF;
        for (int i = 0; i < n; ++i) dp[(1<<i)][i][0] = dp[(1<<i)][i][1] = dis(x[0][i], y[0][i], x[1][i], y[1][i]);
        
        for (int bit = 0; bit < (1<<n); ++bit) {
            for (int i = 0; i < n; ++i) {
                //cout << bitset<4>(bit) << ", " << i << " : " << MP(dp[bit][i][0], dp[bit][i][1]) << endl;
                if ( !(bit & (1<<i)) ) continue;
                for (int j = 0; j < n; ++j) {
                    if (i == j) continue;
                    if (bit & (1<<j)) continue;
                    int nbit = bit | (1<<j);
                
                    for (int p = 0; p < 2; ++p) for (int q = 0; q < 2; ++q) {
                        chmin(dp[nbit][j][1-q], dp[bit][i][p] + dis(x[p][i], y[p][i], x[q][j], y[q][j]) 
                              + dis(x[0][j], y[0][j], x[1][j], y[1][j]));
                    }
                }
            }
        }
        
        double res = INF;
        for (int i = 0; i < n; ++i) chmin(res, dp[(1<<n)-1][i][0]), chmin(res, dp[(1<<n)-1][i][1]);
        
        cout << "Case " << it << ": ";
        cout << fixed << setprecision(9) << res << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 560
memory_kb: 16664
final_rank: 17