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. task.delay 和 thread.sleep

    1.Thread.Sleep 是同步延迟. Task.Delay异步延迟. 2.Thread.Sleep 会阻塞线程,Task.Delay不会. 3.Thread.Sleep不能取消,Task.Del ...

  2. HashMap、Hashtable、HashSet三种hash集合的区别

    转载:http://www.cnblogs.com/lzrabbit/p/3721067.html#h1 HashMap和Hashtable的区别 两者最主要的区别在于Hashtable是线程安全,而 ...

  3. C++入门经典-例5.7-调用自定义函数交换两变量值,传入指针

    1:代码如下: // 5.7.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> using ...

  4. Java8 Optional && Guava Optional

    Java8 -- Optional boolean isPresent():与obj != null()一样:调用get()前要调用isPresent()检查,不然会报错 Optional的三种构造方 ...

  5. 【攻克RabbitMQ】常见问题

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/zlt995768025/article/ ...

  6. spark 笔记 1: 如何着手

    必读:从官方的开发者页面着手,包括如何构建spark以及编码规范(强烈建议读读编程规范)等:https://cwiki.apache.org/confluence/display/SPARK/Cont ...

  7. 开源EDR(OSSEC)基础篇- 02 -部署环境与安装方式

    https://yq.aliyun.com/articles/683077?spm=a2c4e.11163080.searchblog.9.753c2ec1lRj02l

  8. 查询一个redis集群的大keys 脚本

    1. 把redis集群中的 master 节点信息记录在文件 redis_object_port.info 中, 方便下一步遍历各实例中的大 keys redis-cli -h 10.240.47.1 ...

  9. UNITY相关的一些新功能,新想法

    1,lua profiler for unity : https://github.com/ElPsyCongree/LuaProfiler-For-Unity 参考文章:https://blog.c ...

  10. 1.7 本机单步调试(Intellij IDEA)

    先编译好要调试的程序. 1.设置断点 选定要设置断点的代码行,在行号的区域后面单击鼠标左键即可. 2.开启调试会话 点击红色箭头指向的小虫子,开始进入调试. IDE下方出现Debug视图,红色的箭头指 ...