题目大意:给出2*n个点,将这些点配成n对,使得所有点对中两点的距离之和尽量小。

  用一个整数的二进制形式表示一个集合的子集,以每个集合为状态进行状态转移。具体参见《算法竞赛入门经典》9.5。

 #include <cstdio>
#include <cmath>
#include <algorithm>
#include <cfloat>
using namespace std; struct Point
{
int x, y;
} point[];
double dp[<<+]; double dis(int a, int b)
{
int x_diff = point[a].x - point[b].x;
int y_diff = point[a].y - point[b].y;
return sqrt(x_diff * x_diff + y_diff * y_diff);
} int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
int n, kase = ;
char name[];
while (scanf("%d", &n) && n)
{
n *= ;
for (int i = ; i < n; i++)
scanf("%s%d%d", name, &point[i].x, &point[i].y);
dp[] = ;
for (int s = ; s < (<<n); s++)
{
dp[s] = DBL_MAX;
int p = ;
for ( ; p < n; p++)
if (s & (<<p)) break;
for (int i = p+; i < n; i++)
if (s & (<<i))
dp[s] = min(dp[s], dis(p, i)+dp[s^(<<p)^(<<i)]);
}
printf("Case %d: %.2lf\n", ++kase, dp[(<<n)-]);
}
return ;
}

UVa 10911 - Forming Quiz Teams的更多相关文章

  1. uva 10911 - Forming Quiz Teams(记忆化搜索)

    题目链接:10911 - Forming Quiz Teams 题目大意:给出2 * n个选手的坐标, 要求将所有的选手分成n组, 每组两个人, 所有组的两个人之间的距离之和要最小, 输出最小值. 解 ...

  2. UVA 10911 Forming Quiz Teams(dp + 集合最优配对问题)

    4th IIUC Inter-University Programming Contest, 2005 G Forming Quiz Teams Input: standard input Outpu ...

  3. 集合上的动态规划---最优配对问题(推荐:*****) // uva 10911

    /* 提醒推荐:五星 刘汝佳<算法竞赛入门经典>,集合上的动态规划---最优配对问题 题意:空间里有n个点P0,P1,...,Pn-1,你的任务是把它们配成n/2对(n是偶数),使得每个点 ...

  4. UVa 11609 (计数 公式推导) Teams

    n个人里选k个人有C(n, k)中方法,再从里面选一人当队长,有k中方法. 所以答案就是 第一步的变形只要按照组合数公式展开把n提出来即可. #include <cstdio> typed ...

  5. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  6. 算法入门经典大赛 Dynamic Programming

    111 - History Grading LCS 103 - Stacking Boxes 最多能叠多少个box DAG最长路 10405 - Longest Common Subsequence ...

  7. Codeforces 552 E. Two Teams

    E. Two Teams time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  8. Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) Volume 5. Dynamic Programming

    10192 最长公共子序列 http://uva.onlinejudge.org/index.php?option=com_onlinejudge& Itemid=8&page=sho ...

  9. SPOJ:Harbinger vs Sciencepal(分配问题&不错的DP&bitset优化)

    Rainbow 6 is a very popular game in colleges. There are 2 teams, each having some members and the 2 ...

随机推荐

  1. 转:LR的响应时间与使用IE所感受时间不一致的讨论

    在做性能测试时,有时碰到这样一种情况,使用性能工具LR测试出来的响应时间比实际使用IE感受到的时间要长,例如,实际使用IE打开一个系统时只需要1~2秒,而使用LR跑一个用户所得出的结果可能是8秒.10 ...

  2. 逆序一个8bit的2进制数

  3. HDU 3691 Nubulsa Expo

    无向图的最小割.套了个模板. #include<iostream> #include<cstdio> #include<cstring> #include<a ...

  4. 错误: error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. 的处理方法

  5. asp 特殊字符替换

    <%Function specialstr(yourstring)find= "¿,À,Á,Â,Ã,Ä,Å,Æ,Ç,È,É,Ê,Ë,Ì,Í,Î,Ï,Ð,Ñ,Ò,Ó,Ô,Õ,Ö,Ø,Ù, ...

  6. 一个web项目在myeclipse中add deployment时无法被识别出来的原因

    当我们一个web项目,在myeclipse中,add deployment时,可能发现,根本无法被识别成web项目,可能的原因有:   1. 项目的properties ->Myeclipse ...

  7. Delphi版IP地址与整型互转

    Delphi版IP地址与整型互转 unit Unit11; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphic ...

  8. UIApplication 用法解析

    UIApplication,代表的是整个应用做的事,因此每个程序只能有一个,系统使用的是单例模式,就是上面的[UIApplication sharedApplication]来得到一个实例.这个单例实 ...

  9. Java中的字符串分割 .

    转自 http://blog.csdn.net/yuwenhao0518/article/details/7161059 http://longkm.blog.163.com/blog/static/ ...

  10. zencart 具体页面调用规则: $body_code变量解析

    zencart $body_code变量解析 修改centerColumn 可以修改中间产品方框的大小 2.2.5 .BODY文件在这个文件生效 require($body_code) include ...