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 ...
随机推荐
- MySQL+heartbeat+nfs做高可用
一.环境准备节点两个node1:10.10.10.202node2:10.10.10.203nfs服务器:node3:10.10.10.204系统环境CentOS release 6.5 (Final ...
- Yii config 配置
Yii2 配置文件 常用配置总结 <?php // 主配置文件 $config = array( 'modules' => array( 'gii' => array( 'class ...
- MySQL架构优化:定时计划任务与表分区
转自: MySQL架构优化实战系列3:定时计划任务与表分区 - 今日头条(TouTiao.com)http://toutiao.com/a6304736482361049345/?tt_from=mo ...
- 剑指offer 调整数组顺序使得奇数位于偶数前面
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 class Solution { public: void ...
- javascript之定义函数时 this 和prototype区别
注:原文 http://www.2cto.com/kf/201406/307790.html 这里作为学习,写在这里 在面向对象的方式编写js脚本时,定义实例的方法主要有两种:this.XXX = f ...
- Why attitude is more important than IQ
原文:http://www.businessinsider.com/why-attitude-is-more-important-than-iq-2015-9?IR=T& LinkedIn I ...
- 转 通过 spring 容器内建的 profile 功能实现开发环境、测试环境、生产环境配置自动切换
软件开发的一般流程为工程师开发 -> 测试 -> 上线,因此就涉及到三个不同的环境,开发环境.测试环境以及生产环境,通常 ...
- ural1682 Crazy Professor
Crazy Professor Time limit: 1.0 secondMemory limit: 64 MB Professor Nathan Mathan is crazy about mat ...
- CentOS 6.5搭建Samba服务器
目标需求:在Windows7下访问CentOS 6.5 root用户桌面/ZS文件夹 0.准备工作 关闭防火墙并开启不起动 service iptables stop chkconfig iptabl ...
- Hadoop: failed on connection exception: java.net.ConnectException: Connection refuse
ssh那些都已经搞了,跑一个书上的例子出现了Connection Refused异常,如下: 12/04/09 01:00:54 INFO ipc.Client: Retrying connect t ...