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),每个作业需耗时,有一个截止期限.超期多少天就要扣多少 ...
随机推荐
- 2-SAT (two-statisfiability) 算法 学习笔记
$2-SAT$问题指的是对于若干限制求出一组可行解的问题. 考虑对于$n$个值域为${0,1}$的变量$x_1 , x_2 ,...,x_n$ 满足若干限制: 若 $x_i = p$ 则 $x_j = ...
- 'vue' 不是内部或外部命令,也不是可运行的程序 或批处理文件
解决方案:找到npm i xxx -g 下载后存放的路径,将路径添加到环境变量中,即可.1.npm config list 查看一下npm 的配置信息 2.打开路径看看里面的命令.window用户wi ...
- 【转】稳定婚姻问题(Stable Marriage Problem)
转自http://www.cnblogs.com/drizzlecrj/archive/2008/09/12/1290176.html 稳定婚姻是组合数学里面的一个问题. 问题大概是这样:有一个社团里 ...
- html5 代码画兰博基尼跑车,6不6你说的算!
源代码下方 由于本人喜爱html5,无聊所画: 画图需要掌握; 1.画布,画笔,画圆,给画笔添加颜色.(注:掌握这几点,你就可以称霸画图界了.) 虽然没有画画天赋,但代码写的也是溜溜滴!(注:此图没有 ...
- DVWA--CRSF
首先我们对CRSF进行一个介绍 CSRF,全称Cross-site request forgery,翻译过来就是跨站请求伪造,是指利用受害者尚未失效的身份认证信息(cookie.会话等),诱骗其点击恶 ...
- 分布式-信息方式-ActiveMQ的Destination高级特性3
虚拟destination用来创建逻辑destination,客户端可以通过它来生产和消费消息,它会把消息映射到物理destination. ActiveMQ支持2种方式: 1:虚拟主题(Virtua ...
- 黑马lavarel教程---6、简单验证
黑马lavarel教程---6.简单验证 一.总结 一句话总结: 1.验证的最简单实例:$request的validate方法,验证通过可以继续进行,验证失败就重定向 2.中文提示可以用中文语言包 3 ...
- spark 笔记 14: spark中的delay scheduling实现
延迟调度算法的实现是在TaskSetManager类中的,它通过将task存放在四个不同级别的hash表里,当有可用的资源时,resourceOffer函数的参数之一(maxLocality)就是这些 ...
- 前端学习框架之layui
学习地址:https://www.layui.com/demo/laytpl.html
- Spring Data JPA 动态拼接条件的通用设计模式
import java.sql.Timestamp;import java.util.ArrayList;import java.util.List;import javax.persistence. ...