题目大意

给你n个点,其中一些点是固定的,然后还有一些没有固定的,然后问你固定所有点所用的线段的最小长度是多少。

所谓固定,就是形如三角形的情况,就是两个固定的点向一个未固定的点连两条边,就能把未固定的点固定。

数据范围

1 <= n <= 18

分析

感觉这简单的状压长得跟搜索似得

#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string.h>
using namespace std;
const int MAX = 19;
const int INF = 2147000047;
inline int read() {
char ch = getchar(); int f = 1, x = 0;
while(ch<'0' || ch>'9') {if(ch=='-') f = -1; ch = getchar();}
while(ch>='0' && ch<='9') {x = x*10+ch-'0'; ch = getchar();}
return x*f;
} int n, sta, is;
double f[1<<MAX];
struct node{
double x, y;
}arr[MAX]; double juli(double x1, double y1, double x2, double y2) {
return sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );
}
double min_juli(int s, int j) {//当前状态s,新插入点j,返回插入后状态s`的f
double min1 = INF, min2 = INF, tmp;
for(int i = 1; i <= n; i++)
if(s&(1<<(i-1))) {
tmp = juli(arr[i].x, arr[i].y, arr[j].x, arr[j].y);
if(tmp <= min1) min2 = min1, min1 = tmp;
else if(tmp < min2) min2 = tmp;
}
return min1+min2;//暂不考虑 不存在min
} void pre() {
memset(arr, 0, sizeof(arr));
for(int i = 1; i < (1<<n); i++) f[i] = INF;
sta = 0;
for(int i = 1; i <= n; i++) {
arr[i].x = read(), arr[i].y = read(), is = read();
sta |= (is<<(i-1));
}
f[sta] = 0;
}
void solve() {
int tmp;
for(int i = sta; i < (1<<n); i++) if((i&sta) == sta) {
tmp = (~i & ((1<<n)-1));
// printf("i: %d, 取0:%d\n", i, tmp);
for(int j = 1; j <= n; j++) if(tmp&(1<<(j-1))) {
// printf("j: %d,插入之后: %d\n", j, i|(1<<(j-1)));
f[i|(1<<(j-1))] = min(f[i|(1<<(j-1))], f[i] + min_juli(i, j));
}
}
if(f[(1<<n)-1] >= INF) printf("No Solution\n");
else printf("%.6f\n", f[(1<<n)-1]);
} int main() {
while(scanf("%d",&n) && n) {
pre();
solve();
}
return 0;
}

JDOJ1100: Fix的更多相关文章

  1. PhpStorm和WAMP配置调试参数,问题描述Error. Interpreter is not specified or invalid. Press “Fix” to edit your project configuration.

    PhpStorm和WAMP配置调试参数 问题描述: Error. Interpreter is not specified or invalid. Press “Fix” to edit your p ...

  2. No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

    Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...

  3. Eclipse ndk fix插件开发

    一. 手工修复ndk环境bug Eclipse做ndk开发的时候, 经常会遇到编译过去,却报语法错误的问题,比如 ①. 头文件不识别 ②. 头文件识别了, 类型不识别 针对这一的bug,我们一般按照如 ...

  4. How to Fix GNOME License Not Accepted Issue on CentOS 7

    This post assume that you have just finished the Gnome GUI installation on CentOS 7 by using “yum gr ...

  5. Nodemanager Out of heap memory[fix bug全过程]

    问题: 自己写了一个yarn上的application,发现nodemanager过段时间,会out of memory退出,把nodemanager的heap memory从1G增大到2G也是无法避 ...

  6. mathlab之floor,ceil,round,int以及fix函数

    建议自己动手敲敲,网上很多人自己都没搞清楚然后好多错的.毕竟自己亲眼看到结果才有说服力. 以下是我亲眼见到的结果. 1.double floor(double)函数 floor()函数是常用的取整函数 ...

  7. matlab size、numel、length、fix函数的使用,补充nargin

    size():获取矩阵的行数和列数 (1)s=size(A), 当只有一个输出参数时,返回一个行向量,该行向量的第一个元素时矩阵的行数,第二个元素是矩阵的列数.(2)[r,c]=size(A), 当有 ...

  8. Can't use Subversion command line client: svn Probably the path to Subversion executable is wrong. Fix it.

    1.最近使用SVN工具时,Checkout出项目到本地后后,然后将其导入到Intellij idea中开发,在提交svn代码的时候,出现这样的错误:Can't use Subversion comma ...

  9. 自定义母版页之列表过滤菜单位置issue fix

    问题描述: 自定义母版页,为了使左边导航和顶部导航位置不变(不滚动),将原本位于ribbon下方的#s4-workspace调整到左侧导航右边. <div id="s4-workspa ...

随机推荐

  1. 教你两招用纯CSS写Tab切换

    说到Tab切换,你可能首先想到的就是使用jQuery,短短几行代码就可以轻松搞定一个Tab切换. 而今天所要分享的,是使用 0 行JS代码来实现Tab切换! 具体效果如下:   Tab切换 方法一:模 ...

  2. Linux CentOS 6.5 卸载、安装JDK1.8

    卸载系统自带的jdk 1. 查询系统是否已经安装了jdk rpm -qa|grep java 2. 卸载已安装的jdk, 系统可能会自带多个jdk版本, 按需卸载 rpm -e --nodeps ja ...

  3. 8. Vue - Router

    一.Vue Router 的使用 JavaScript: 1.创建组件:创建单页面应用需要渲染的组件 2.创建路由:创建VueRouter实例 3.映射路由:调用VueRouter实例的map方法 4 ...

  4. JavaScript 代码执行顺序

    一.先预处理后执行 在一个JavaScript文件或一个JavaScript代码块的内部,浏览器会先对代码进行预处理(编译),然后再执行. 预处理会跳过执行语句,只处理声明语句,同样也是按从上到下按顺 ...

  5. LVS 负载均衡——直接路由模式DR

    一.配置的网络拓扑结构图 二.配置lvs服务器 配置虚拟网卡地址(VIP地址) [root@localhost ~]# ifconfig eno16777728: 192.168.200.253 ne ...

  6. servlet重点知识总结

    Servlet Java Servlet 是运行在 Web 服务器或应用服务器上的程序,它是作为来自 Web 浏览器或其他 HTTP 客户端的请求和 HTTP 服务器上的数据库或应用程序之间的中间层. ...

  7. Codeforces Round #594 (Div. 1) C. Queue in the Train 模拟

    C. Queue in the Train There are

  8. golang--海量用户即使通讯系统

    功能需求: 用户注册 用户登录 显示在线用户列表 群聊 点对点聊天 离线留言

  9. 对js的有感而发

    1.什么是JavaScript?他是一个脚本语言,也是一种解释性语言,也是一种弱类型语言.2,当我们学习JavaScript时我们肯定要知道,js的组成是什么? 应该怎么用?这些是最基础的.js的组成 ...

  10. MongoDB创建集合和删除集合05-14学习笔记

    MongoDB 是一个基于分布式文件存储的数据库.由 C++ 语言编写,是一个基于分布式文件存储的开源数据库系统.旨在为 WEB 应用提供可扩展的高性能数据存储解决方案. MongoDB 是一个介于关 ...