题目大意

给你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. How to restore and recover a database from an RMAN backup. (Doc ID 881395.1)

    APPLIES TO: Oracle Database - Enterprise Edition - Version 10.1.0.2 to 11.2.0.2 [Release 10.1 to 11. ...

  2. Linux开发环境搭建三 使用mount -t cifs 挂载windows共享目录方法与问题解决

    转载链接:https://blog.csdn.net/fuyuande/article/details/82915800 嵌入式开发通常是在linux环境下编译,windows下开发,这就需要在lin ...

  3. 005.MongoDB索引及聚合

    一 MongoDB 索引 索引通常能够极大的提高查询的效率,如果没有索引,MongoDB在读取数据时必须扫描集合中的每个文件并选取那些符合查询条件的记录. 这种扫描全集合的查询效率是非常低的,特别在处 ...

  4. Codeforces Round #598 (Div. 3)

    传送门 A. Payment Without Change 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/4 21:19:19 */ #i ...

  5. OSPF和ACL的应用

    1.创建拓扑图 2.配置基本网络 3.配置OSPF (1)在R1上配置 (2)在R2上配置 (3)在R3上配置 (4)在IT上配置 4.配置ACL (1)在R3上配置    (2)在R2上配置 (3) ...

  6. testNG常用用法总结

    一.testNG介绍 TestNG是Java中的一个测试框架, 类似于JUnit 和NUnit,   功能都差不多, 只是功能更加强大,使用也更方便 Java中已经有一个JUnit的测试框架了.  T ...

  7. Make Them Odd

    time limit per test3 secondsmemory limit per test256 megabytesinput: standard inputoutput: standard ...

  8. LVS负载均衡实现双向热备

    一.LVS1服务器配置 安装ipvsadm,keepalived [root@localhost ~]# yum -y install ipvsadm keepalived 配置keepalivedd ...

  9. linux 判断文件夹或文件是否存在

    文件夹不存在则创建 if [ ! -d "/data/" ];then mkdir /data else echo "文件夹已经存在" fi 文件存在则删除 i ...

  10. Google工作法

    本文转自:https://www.yuque.com/heqingbao/msfy2c/zg56gm 这几天去上海参加Google开发者大会,利用空闲时间读了一本快餐书,书名叫<Google工作 ...