HNUSTOJ-1621 Picking Cabbage(状态压缩DP)
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
输入
输出
样例输入
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)的更多相关文章
- hoj2662 状态压缩dp
Pieces Assignment My Tags (Edit) Source : zhouguyue Time limit : 1 sec Memory limit : 64 M S ...
- POJ 3254 Corn Fields(状态压缩DP)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4739 Accepted: 2506 Descr ...
- [知识点]状态压缩DP
// 此博文为迁移而来,写于2015年7月15日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102w6jf.html 1.前 ...
- HDU-4529 郑厂长系列故事——N骑士问题 状态压缩DP
题意:给定一个合法的八皇后棋盘,现在给定1-10个骑士,问这些骑士不能够相互攻击的拜访方式有多少种. 分析:一开始想着搜索写,发现该题和八皇后不同,八皇后每一行只能够摆放一个棋子,因此搜索收敛的很快, ...
- DP大作战—状态压缩dp
题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...
- 状态压缩dp问题
问题:Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Ev ...
- BZOJ-1226 学校食堂Dining 状态压缩DP
1226: [SDOI2009]学校食堂Dining Time Limit: 10 Sec Memory Limit: 259 MB Submit: 588 Solved: 360 [Submit][ ...
- Marriage Ceremonies(状态压缩dp)
Marriage Ceremonies Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- HDU 1074 (状态压缩DP)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:有N个作业(N<=15),每个作业需耗时,有一个截止期限.超期多少天就要扣多少 ...
随机推荐
- HGOI20190810 省常中互测3
Problem A 夏洛特 若当前处在点$(x,y)$下一时刻可以向该点四周任意方向走动一步, 初始在$(0,0)$是否存在一条合法的路线满足下列$n$个限制: 每一个限制形如$t_i , x_i ...
- jQuery_CSS类操作
下面讲述jQuery操作css类,进行类的添加,移除,以及前两项功能的结合操作. <!DOCTYPE html> <html> <head> <meta ch ...
- Link Script 学习
最后更新 2019-06-27 概述 当使用 C 或者 C++ 编写代码实现某种功能时,需要将源代码进行编译以及链接.链接是将一系列目标文件(.o)以及归档文件(.a)组合起来,重新定位各个文件数据并 ...
- es6字符串的扩展——模板
todo1.模板字符串 传统的 JavaScript 语言,输出模板通常是这样写的(下面使用了 jQuery 的方法). $('#result').append( 'There are <b&g ...
- Spring boot之使用freemarker
大纲 (1)在pom.xml中引入freemarker; (2)如何关闭freemarker缓存 (3)编写模板文件.ftl (4)编写访问文件的controller 在pom.xml中引入freem ...
- 网页中JS函数自动执行常用三种方法
(1)最简单的调用方式,直接写到html的body标签里面: <body onload="myFunction()"></body> ...
- C++入门经典-例4.11-名称空间的定义和使用
1:名称空间,也成为名字空间.命名空间,关键字为namespace.我们经常使用这样一条语句: using namespace std: 我们要使用标准输入输出流,除了包含它们所在的头文件外,还必须使 ...
- 使用FFmpeg让mp4转gif
配好环境之后,需要在开始菜单中打开命令提示符,然后进入到test.mp4的文件目录下执行命令.(直接在文件目录下打开cmd不能生效)ffmpeg -i test.mp4 -f gif test.gif
- redis扫描特定keys脚本,可避免阻塞,不影响线上业务
#!/bin/sh ## 该脚本用来查询redis集群中,各个实例当中特定前缀的key,对应只需要修改redis的其中一个实例的 host和port## 脚本会自动识别出该集群的所有实例,并查出对应实 ...
- 【编程漫谈】Hello world!
Hello world!是打开编程世界的第一把钥匙,只要你能运行出Hello world!,基本上就算入了个门了,因为程序正确的运行代表着基本开发环境都有了,包括编辑器,编译器,解释器,运行环境等待, ...