白书P61 - 点集配对问题

状压DP

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define INF 0x3f3f3f3f struct Point
{
double x,y,z;
}p[+]; int n;
double dp[(<<)+]; //dp[j]表示j对应状态(0为未配对,1为配对了)的最小距离和 double dist(int i,int j)
{
return sqrt((p[i].x-p[j].x)*(p[i].x-p[j].x)+(p[i].y-p[j].y)*(p[i].y-p[j].y)+(p[i].z-p[j].z)*(p[i].z-p[j].z));
} void solve()
{
int i,j,k,MAX=<<n;
for(i=;i<MAX;i++)
{
dp[i]=1e10;
}
dp[]=; for(j=;j<MAX;j++)
{
for(i=;i<n;i++)
{
if(j&(<<i)) break;
}
for(k=i+;k<n;k++)
{
if(j&(<<k)
{
dp[j]=min(dp[j],dp[(j&(~(<<i)))&(~(<<k))]+dist(i,k));
}
}
}
printf("%lf\n",dp[MAX-]);
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<n;i++)
{
scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z);
}
solve();
}
return ;
}

白书P61 - 点集配对问题的更多相关文章

  1. 白书P60 - 硬币问题

    白书P60 - 硬币问题 完全背包.DP #include <iostream> #include <cstdio> #include <cstring> usin ...

  2. poj2991 Crane(线段树+集合)白书例题

    题目大意:起重机有n节,题目给出要调节的k节,每节调节成x度,求最后底部的起重机的坐标(最顶上的起点为(0,0)). 分析:一开始我看白书,看不懂他那个向量旋转的坐标是怎么来的,翻了很多博客,才发现, ...

  3. Uva10474-STL水题-白书

    白书的一道水题.话说好久没认真做难题了.今天出了排名,所有队伍里倒数第一啊! 代码没什么可说的了. #include <algorithm> #include <cstring> ...

  4. UVA大模拟代码(白书训练计划1)UVA 401,10010,10361,537,409,10878,10815,644,10115,424,10106,465,10494

    白书一:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=64609#overview 注意UVA没有PE之类的,如果PE了显示WA. UVA ...

  5. 《白书》上线段树RMQ的实现

    白书上的线段树RMQ实现,自己重写了一遍: #include <bits/stdc++.h> using namespace std; const int MAXN=1<<17 ...

  6. 点集配对问题(状态dp)

    给定n个点(n是偶数)使得两个点两两配对,最后总的距离和最小. 用是表示集合,那么dp[s]表示集合s配对后的最小距离和  , 状态转换方程为  表示集合中任意拿两个元素配对,然后转移为更小的两个集合 ...

  7. la3523 白书例题 圆桌骑士 双联通分量+二分图

    具体题解看大白书P316 #include <iostream> #include <algorithm> #include <vector> #include & ...

  8. [tem]线段树(白书版)

    个人感觉有点坑 add用的标记永久化 set用的标记下传 #include <iostream> #include <cstdio> #include <algorith ...

  9. 白书 4.1.2 模运算的世界 P291

    1.逆元 这里有个注意事项要说,就是当要求 (a-b)%m 的时候要注意不能直接 (a%m-b%m)%m 原因是得出的值有可能是负数,所以 (a%m-b%m+m)%m 才是正确的. //x,y是引用 ...

随机推荐

  1. 07_XPath_01_入门

    [工程截图] [person.xml] <?xml version="1.0" encoding="UTF-8"?> <students> ...

  2. C语言 goto, return等跳转

    C语言 goto, return等跳转 Please don't fall into the trap of believing that I am terribly dogmatical about ...

  3. XML, XPath, Xslt及解析/Parse

    XML及解析/Parse "Programming with libxml2 is like the thrilling embrace of an exotic stranger.&quo ...

  4. How to: Extract files from a compiled setup.exe created by Inno setup

    Use innounp.exe to unpack setup.exe created by using Inno setup: for example, unpack all the files w ...

  5. Wix: Using Patch Creation Properties - Minor Update

    Based on the project created in Wix: Using Patch Creation Properties - Small Update, Following chang ...

  6. hdu 1063 Exponentiation (高精度小数乘法)

    //大数继续,额,要吐了. Problem Description Problems involving the computation of exact values of very large m ...

  7. centos6.3安装openvpn客户端

    centos6.3安装openvpn客户端 Centos 默认是没有提供Openvpn的,而且在yum 的源里面也没有openvpn ,如果想使用yum安装的话要首先安装EPEL这个东西.www.2c ...

  8. [C#]对象深拷贝

    关键代码: /// <summary> /// 对象深拷贝 /// </summary> /// <typeparam name="T">泛型& ...

  9. CSS浮动特性总结

    1.假设现在CSS中没有浮动(float)属性,那么会变成一个什么样子.我们会发现,目前流行采用浮动方法实现的无论是分栏布局,还是列表排列我们都可以用其他一些CSS属性(不考虑table)代替实现,唯 ...

  10. oracle,wamp,FZ突然出现问题,求解决方案(未解决,最终系统还原)

    -----背景------- 系统:win7  64位oracle 11g(11.1)每天都用oracle.用toad for oracle .电脑固定IP.未更改任何配置信息.用了几个月,突然出现了 ...