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),每个作业需耗时,有一个截止期限.超期多少天就要扣多少 ...
随机推荐
- FFT-Matlab初步实现
/****************************************************/ /******************************************** ...
- Jmeter -- 添加断言,及断言结果
步骤: 1. 添加响应断言(添加-断言-响应断言) Add --> Assertions --> Response Assertion 2. 配置断言 判断响应内容中,是否包含关键字“禅 ...
- 「CEOI2008」order
题目链接 戳我 \(Solution\) 首先看看没有租条件的怎么弄.这很显然,就是普通最小割的套路 \(s\)向每个工作连一条流量\(x\)的边,\(x\)为工作收益 每个工作向每个机器连流量为\( ...
- 分布式-信息方式-ActiveMQ构建应用
ActivemQ构建应用Broker:相当于一个 ActiveMQ服务器实例命令行启动参数示例如下:1 ...
- ES6迭代器和生成器
一.迭代器 JavaScript 原有的表示"集合"的数据结构,主要是数组(Array)和对象(Object),ES6 又添加了Map和Set.这样就需要一种统一的接口机制,来处理 ...
- Struts2拦截器和过滤器的区别?
①过滤器依赖于Servlet容器,而拦截器不依赖于Servlet容器. ②Struts2 拦截器只能对Action请求起作用,而过滤器则可以对几乎所 有请求起作用. ③拦截器可以访问 Action上下 ...
- TensorFlow线性回归
目录 数据可视化 梯度下降 结果可视化 数据可视化 import numpy as np import tensorflow as tf import matplotlib.pyplot as plt ...
- 后盾网lavarel视频项目---lavarel多表关联一对多操作实例
后盾网lavarel视频项目---lavarel多表关联一对多操作实例 一.总结 一句话总结: 1.一对多中多那个部分的数据前端通过json弄到服务器 2.所有通过一操作多的时候,都要用上模型中定义的 ...
- du和df目录大小不一致
最近遇到个问题 df查看基本没有空间了 但是查找大文件 也基本没有 ,原来是之前的大文件删除了 没有生效导致的 用如下命令,查找到相关进程ID 然后kill就行了 lsof | grep delete ...
- json -- fastjson如何序列化@Transient的字段
今天把fastjson包改成了1.2.58,发现@Transient标注的字段序列化后不见了,但是项目需要把@Transient字段序列化,处理方法: 原文:https://github.com/al ...