1621: Picking Cabbage

时间限制: 2 Sec  内存限制: 32 MB
提交: 26  解决: 14
[提交][状态][讨论版]

题目描述

Once, Doraemon and  Nobita planted a farm with cabbage. One night their farm was stealed by Takeshi Gian. Takeshi Gian picked away most of the cabbage, but left some cabbage in the farm. Then he left a note to Doraemon and  Nobita, telling them the coordinate of the cabbage still in the farm. As soon as Doraemon and  Nobita get the note, they run out to save their cabbage.

Doraemon has a warp gate in his house that can send them to a cabbage which they wanted to. Then they should run from one cabbage to another to get them. Since they wanted to get all the cabbage as soon as possible, they should run the shortest way. Can you calculate the shortest path that they should run

输入

There are multiple test cases. The first line is a positive integer stands for the number of test cases.
The first line of each test case is a positive integer N(1<=N<=15) stands for the number of cabbage that Takeshi Gian left.
Then N following lines each has two integer xi, yi, (0<=xi,yi<=100) stands for the coordinate of the cabbage.

输出

Output the shortest path of getting all the cabbage in one line keeping two decimal places.
Doraemon and  Nobita just wanted to get all of the cabbage as soon as possible, so, don't bother about their path of getting back home.

样例输入

2
3
0 0
0 1
0 2
3
0 0
0 1
1 0

样例输出

2.00
2.00
状态压缩DP
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio> using namespace std;
const int N = ;
const int M = (<<);
const double INF = (<<);
double dp[N][M];
int x[N], y[N], n, u; inline double dist(int v, int i){
return sqrt((x[v] - x[i]) * (x[v] - x[i]) + (y[v] - y[i]) * (y[v] - y[i]));
} double DP(int v, int S){
if(dp[v][S]) return dp[v][S];
auto M = INF; S |= ( << v);
for(int i = ; i < n; ++ i)
if( !(S & ( << i)))
M = min(M, DP(i, S) + dist(v, i));
S &= (~( << v)); return dp[v][S] = (M != INF? M : );
} int main(){
int T;
scanf("%d", &T);
while(T --){
memset(dp, , sizeof(dp));
scanf("%d", &n);
for(int i = ; i < n; ++ i){
scanf("%d %d", &x[i], &y[i]);
}
auto Min = INF;
for(int i = ; i < n; ++ i){
Min = min(Min, DP(i, ));
}
printf("%.2f\n", Min);
}
return ;
}
 

HNUSTOJ-1621 Picking Cabbage(状态压缩DP)的更多相关文章

  1. hoj2662 状态压缩dp

    Pieces Assignment My Tags   (Edit)   Source : zhouguyue   Time limit : 1 sec   Memory limit : 64 M S ...

  2. POJ 3254 Corn Fields(状态压缩DP)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4739   Accepted: 2506 Descr ...

  3. [知识点]状态压缩DP

    // 此博文为迁移而来,写于2015年7月15日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102w6jf.html 1.前 ...

  4. HDU-4529 郑厂长系列故事——N骑士问题 状态压缩DP

    题意:给定一个合法的八皇后棋盘,现在给定1-10个骑士,问这些骑士不能够相互攻击的拜访方式有多少种. 分析:一开始想着搜索写,发现该题和八皇后不同,八皇后每一行只能够摆放一个棋子,因此搜索收敛的很快, ...

  5. DP大作战—状态压缩dp

    题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...

  6. 状态压缩dp问题

    问题:Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Ev ...

  7. BZOJ-1226 学校食堂Dining 状态压缩DP

    1226: [SDOI2009]学校食堂Dining Time Limit: 10 Sec Memory Limit: 259 MB Submit: 588 Solved: 360 [Submit][ ...

  8. Marriage Ceremonies(状态压缩dp)

     Marriage Ceremonies Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  9. HDU 1074 (状态压缩DP)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:有N个作业(N<=15),每个作业需耗时,有一个截止期限.超期多少天就要扣多少 ...

随机推荐

  1. 1209F - Koala and Notebook

    这场比赛没打,看同学fst了,于是来看看. 这道题看似简单,但是没想清楚细节真的不太行.像现在熬到十一点左右,脑子真的不行. 首先显然位数越小越好,因为每一位要比较,不如拆点.此时要拆成两条有向链(开 ...

  2. 论文阅读:Fast, Scalable, and Programmable Packet Scheduler in Hardware

    摘要: 随着链接速度的提高和CPU扩展速度的放缓,软件中的数据包调度会导致较低的精度和较高的CPU利用率. 通过将数据包调度卸载到诸如NIC之类的硬件,可以潜在地克服这些缺点.然而为了保持软件分组调度 ...

  3. Spring-data-redis 第一天

    1.Redis 这就不必哆嗦了,Redis 支持丰富的数据类型,String ,List,Sets ,Sorted Sets,Hashes,这就可以看出Java 操作Redis就要针对各种类型都有自己 ...

  4. css3 水纹效果(仿写阿里云)

    效果图 什么也不说了,上代码. <!DOCTYPE html> <html> <head> <title>css3 水纹效果</title> ...

  5. C++如何限制对象在堆上或栈上生成

    1,限制类的对象只能生成在栈上 将 operator new 各种原型设为私有 #include <iostream> class OnlyOnStack { public: OnlyOn ...

  6. 有关二次离线和 Yuno loves sqrt technology II

    二次离线 前置技能 莫队 修改查询 \(O(\sqrt n )-O(1)\) 平衡 概念 考虑朴素莫队离线询问,过程中维护信息从 \([l,r]\) 扩展为 \([l\pm 1,r\pm 1]\) , ...

  7. 浏览器端-W3School-JavaScript:JavaScript Number 对象

    ylbtech-浏览器端-W3School-JavaScript:JavaScript Number 对象 1.返回顶部 1. JavaScript Number 对象 Number 对象 Numbe ...

  8. 服务器被攻击后当作矿机,高WIO

    __ 矿机特点:    操作系统反应慢. wio 非常高,一般轻松达到50%,甚至达到100%. 在/root/ 下存在 .ddg 隐藏路径.路径中有nnnn.db 二进制文件. /tmp ./usr ...

  9. 阶段3 2.Spring_08.面向切面编程 AOP_4 spring基于XML的AOP-配置步骤

    resources下新建bean.xml文件 xmlns:aop 先配置IOC aop 通知类就是logger.id配置为logAdvice表示日志的通知 梳理流程 首先我们在这有个Service它需 ...

  10. mysql--创建表,插入数据,修改表名,删除表,简单查询/内连接、左/右连接

    创建表mm:  其中id为主键且自增长 ) primary key not null unique auto_increment, name ) not null, age ), class ) no ...