The main topic: there are 2 * n points, so that they make up n pairs, the sum of the minimum distance of N to the point set.
Problem-solving ideas: Because 2 * n maximum is 20, can be represented by the number of bits, each number represents a state, and then to the memory of the search method to produce results.
#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace STD;intNDoubledp[1<< -], dis[ -][ -];DoubleCalintXintY) {return sqrt(x * x + y * y);}DoubleDPS (intS) {if(Dp[s] | |! SreturnDp[s];intI for(i = N-1; I >=0; i--)if(S & (1<< i)) Break; Dp[s] =0x3f3f3f3f; for(intj = i-1; J >=0; j--)if(S & (1<< j)) Dp[s] = min (Dp[s], dis[i][j] + DPS (S ^ (1<< i) ^ (1<< (j)));returnDp[s];}intMain () {intx[ -], y[ -], Kase =0; while(scanf("%d", &n), n) {n <<=1; for(inti =0; i < N; i++)scanf("%*s%d%d", &x[i], &y[i]); for(inti =0; i < N; i++) for(intj = i +1; J < N; J + +) Dis[j][i] = cal (X[i]-x[j], Y[i]-y[j]);memset(DP,0,sizeof(DP));printf("Case%d:%.2lf\n", ++kase, DPS (1<< N)-1)); }return 0;}
UVA-10911 Forming Quiz Teams