UVa 10911 - Forming Quiz Teams
题目大意:给出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的更多相关文章
- uva 10911 - Forming Quiz Teams(记忆化搜索)
题目链接:10911 - Forming Quiz Teams 题目大意:给出2 * n个选手的坐标, 要求将所有的选手分成n组, 每组两个人, 所有组的两个人之间的距离之和要最小, 输出最小值. 解 ...
- UVA 10911 Forming Quiz Teams(dp + 集合最优配对问题)
4th IIUC Inter-University Programming Contest, 2005 G Forming Quiz Teams Input: standard input Outpu ...
- 集合上的动态规划---最优配对问题(推荐:*****) // uva 10911
/* 提醒推荐:五星 刘汝佳<算法竞赛入门经典>,集合上的动态规划---最优配对问题 题意:空间里有n个点P0,P1,...,Pn-1,你的任务是把它们配成n/2对(n是偶数),使得每个点 ...
- UVa 11609 (计数 公式推导) Teams
n个人里选k个人有C(n, k)中方法,再从里面选一人当队长,有k中方法. 所以答案就是 第一步的变形只要按照组合数公式展开把n提出来即可. #include <cstdio> typed ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- 算法入门经典大赛 Dynamic Programming
111 - History Grading LCS 103 - Stacking Boxes 最多能叠多少个box DAG最长路 10405 - Longest Common Subsequence ...
- Codeforces 552 E. Two Teams
E. Two Teams time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 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 ...
- 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 ...
随机推荐
- Ubuntu 12.04和Windows 7双系统安装图解
http://wenku.baidu.com/link?url=PZlnNOhY0SjHDW-teFFnCMzPYJVjx7vj6yWY-o5HHFLuFqhLI4uFcQVu_y0_6i7vpSnz ...
- C#实现http断点下载
我们寄希望于万能的解决方案,但是现实的情况总是很糟糕.在软件编程的世界中,技术分散的情况尤为严重,且不说各种语言拥有的优势不能融合,单就一门语言而言,就拥有众多的技术和相关技术需要学习.网络编程就是这 ...
- VLAN及Trunk实验
VLAN及Trunk实验 一 基本VLAN试验 实验拓扑: 实验目的:掌握VLAN基本配置 掌握静态接口VLAN划分 实验需求:在交换机switch上面创建两个VLAN,vlan2和vlan3,vla ...
- android zip解压缩
android zip解压缩 public class ZipUtils { public ZipUtils() { } /* 以输入流的形式解压 */ public static void UnZ ...
- 关于MyEclipse不停报错multiple problems have occurred 或者是内存不足 的解决办法
这是因为 worksapace与svn代码不一样,要更新! 一更新就好了,困扰死我了,卧槽,搞了2个小时,难怪svn一提交就卡死人,原来还就是svn的问题,更新一下就行.
- 手写js代码(一)javascript数组循环遍历之forEach
注:原文地址http://blog.csdn.net/oscar999/article/details/8671546 我这里是仿照学习! 1.js的数组循环遍历 ①数组的遍历首先想到的是for()循 ...
- javascript中的正则匹配函数exec(),test(),match()
test() var str = "cat";var reStr = /cat/;alert(reStr.test(str)); 输出为:true 它的返回值为true or fa ...
- 2016沈阳网络赛 QSC and Master
QSC and Master Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 绑定网关mac,防arp攻击
netsh i i show innetsh -c i i add neighbors 16 192.168.1.1 08-57-00-51-19-7c
- phpstorm9如何配置interpreter
找到php.exe的路径. 把php.exe 放进去就ok了