题目大意

给你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. Impala基于内存的SQL引擎的详细介绍

    一.简介 1.概述 Impala是Cloudera公司推出,提供对HDFS.Hbase数据的高性能.低延迟的交互式SQL查询功能. •基于Hive使用内存计算,兼顾数据仓库.具有实时.批处理.多并发等 ...

  2. powershell之utf-8编码

    每次启动powershell后输入:chcp 65001

  3. 站点部署,IIS配置优化指南[转]

    站点部署,IIS配置优化指南 目录 一.       设置应用程序池默认设置 二.       常规设置 三.       优化回收策略 四.       性能 五.       IIS初始化(预加载 ...

  4. C++内置二分查找用法

    c++内置二分查找 #include < algorithm > 一.binary_search:查找某个元素是否出现.函数模板:binary_search(arr[], arr[]+si ...

  5. python接口自动化5-session关联

    前言 我们不难发现浏览器中存在着cookie缓存等,但我们在python中如果像浏览器这样的缓存,我们就很难的需要关联cookie或会话了. 但python的requests库,就封装了Session ...

  6. 05爬虫-requests模块基础(2)

    今日重点: 1.代理服务器的设置 2.模拟登陆过验证码(静态验证码) 3.cookie与session 4.线程池 1.代理服务器的设置 有时候使用同一个IP去爬取同一个网站,久了之后会被该网站服务器 ...

  7. HTTP常见的几种认证机制

    几种常用的认证机制 ===================转自https://www.cnblogs.com/xiekeli/红心李的文章====================== 我是一个测试人员 ...

  8. ASP.NET 数据绑定

    控件绑定数据源控件手动方式: DataSourceID = 数据源控件名称下拉框绑定 A.设置Datasource B.DataTextField="name"' //显示的值 C ...

  9. linux的ls命令详解

    概述 Linux ls命令用于显示指定工作目录下之内容(列出目前工作目录所含之文件及子目录). 语法 ls [-alrtAFR] [name...] 参数 -a 显示所有文件及目录 (ls内定将文件名 ...

  10. MongoDB for OPS 03:分片 shard 集群

    写在前面的话 上一节的复制集也就是主从能够解决我们高可用和数据安全性问题,但是无法解决我们的性能瓶颈问题.所以针对性能瓶颈,我们需要采用分布式架构,也就是分片集群,sharding cluster! ...