Codeforces Gym 100610 Problem K. Kitchen Robot 状压DP
Problem K. Kitchen Robot
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/gym/100610
Description
Robots are becoming more and more popular. They are used nowadays not only in manufacturing plants, but also at home. One programmer with his friends decided to create their own home robot. As you may know most programmers like to drink beer when they gather together for a party. After the party there are a lot of empty bottles left on the table. So, it was decided to program robot to collect empty bottles from the table. The table is a rectangle with the length l and width w. Robot starts at the point (xr, yr) and n bottles are located at points (xi , yi) for i = 1, 2, . . . , n. To collect a bottle robot must move to the point where the bottle is located, take it, and then bring to some point on the border of the table to dispose it. Robot can hold only one bottle at the moment and for simplicity of the control program it is allowed to release bottle only at the border of the table. Bottle Bottle Robot l w x y You can assume that sizes of robot and bottles are negligibly small (robot and bottles are points), so the robot holding a bottle is allowed to move through the point where another bottle is located. One of the subroutines of the robot control program is the route planning. You are to write the program to determine the minimal length of robot route needed to collect all the bottles from the table.
Input
The first line of the input file contains two integer numbers w and l — the width and the length of the table (2 ≤ w, l ≤ 1000). The second line of the input contains an integer number n — the number of bottles on the table (1 ≤ n ≤ 18). Each of the following n lines contains two integer numbers xi and yi — coordinates of the i-th bottle (0 < xi < w; 0 < yi < l). No two bottles are located at the same point. The last line of the input file contains two integer numbers xr and yr — coordinates of the robot’s initial position (0 < xr < w; 0 < yr < l). Robot is not located at the same point with a bottle.
Output
Output the length of the shortest route of the robot. Your answer should be accurate within an absolute error of 10−6 .
Sample Input
3 4 2 1 1 2 3 2 1
Sample Output
5.60555127546399
HINT
题意
数据范围已经告诉我们了,这是状压DP……%
题解:
老老实实状压DP就好了
代码:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
using namespace std;
const int maxn = + ;
struct bottle
{
double x,y;
}; int w , l , n , ed ;
double stx,sty;
bottle p[maxn];
double dp[][(<<)+];
bool arrived[][(<<)+]; inline double DIS(double x1,double y1,double x2,double y2)
{
return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * ( y2 - y1));
} double dfs(int x,int y)
{
if(arrived[x][y]) return dp[x][y];
arrived[x][y] = true;
double & ans = dp[x][y] = 1e233;
int sz = ;
if(x == n)
{
for(int i = ; i < n ; ++ i) ans = min( ans , dfs(i , y ) + DIS(stx,sty,p[i].x,p[i].y));
return ans;
}
for(int i = ; i < n ; ++ i) if((y>>i) & ) sz++;
if(sz == ) return ans = min( min(p[x].x , (double)w - p[x].x) , min(p[x].y , (double)l - p[x].y)); //最后一个瓶子
else
{
double x1 = p[x].x;
double y1 = p[x].y;
for(int i = ; i < n ; ++ i)
if((y >> i) & )
{
if(i == x) continue;
double x2 = p[i].x;
double y2 = p[i].y;
double res = 1e233;
res = min( res , DIS(-x1,y1,x2,y2) );
res = min( res , DIS(x1 , -y1,x2,y2));
res = min( res , DIS(2.0*w - x1 , y1 , x2 , y2));
res = min( res , DIS(x1 , 2.0*l - y1,x2,y2));
ans = min( ans , dfs(i , y &(~(<<x)) ) + res);
}
}
return ans;
} int main(int argc,char *argv[])
{
freopen("kitchen.in","r",stdin);
freopen("kitchen.out","w",stdout);
scanf("%d%d%d",&w,&l,&n);
for(int i = ; i < n ; ++ i) scanf("%lf%lf",&p[i].x , &p[i].y);
scanf("%lf%lf",&stx,&sty);
memset(arrived , false , sizeof(arrived));
ed = << n;
printf("%.14lf\n",dfs(n,ed-));
return ;
}
Codeforces Gym 100610 Problem K. Kitchen Robot 状压DP的更多相关文章
- Educational Codeforces Round 13 E. Another Sith Tournament 状压dp
E. Another Sith Tournament 题目连接: http://www.codeforces.com/contest/678/problem/E Description The rul ...
- Codeforces 1225G - To Make 1(bitset+状压 dp+找性质)
Codeforces 题目传送门 & 洛谷题目传送门 还是做题做太少了啊--碰到这种题一点感觉都没有-- 首先我们来证明一件事情,那就是存在一种合并方式 \(\Leftrightarrow\) ...
- Problem Arrangement ZOJ - 3777(状压dp + 期望)
ZOJ - 3777 就是一个入门状压dp期望 dp[i][j] 当前状态为i,分数为j时的情况数然后看代码 有注释 #include <iostream> #include <cs ...
- K - Painful Bases 状压dp
Painful Bases LightOJ - 1021 这个题目一开始看,感觉有点像数位dp,但是因为是最多有16进制,因为限制了每一个数字都不同最多就有16个数. 所以可以用状压dp,看网上题解是 ...
- Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞
Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1006 ...
- Codeforces Gym 100610 Problem A. Alien Communication Masterclass 构造
Problem A. Alien Communication Masterclass Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codefo ...
- Codeforces Gym 100610 Problem E. Explicit Formula 水题
Problem E. Explicit Formula Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...
- CF1103D Codeforces Round #534 (Div. 1) Professional layer 状压 DP
题目传送门 https://codeforces.com/contest/1103/problem/D 题解 失去信仰的低水平选手的看题解的心路历程. 一开始看题目以为是选出一些数,每个数可以除掉一个 ...
- 【Codeforces】Gym 101173B Bipartite Blanket 霍尔定理+状压DP
题意 给一张$n\times m$二分图,带点权,问有多少完美匹配子集满足权值和大于等于$t$ 这里有一个结论:对于二分图$\mathbb{A}$和$\mathbb{B}$集合,如果子集$A \in ...
随机推荐
- 解释一下,在你往浏览器中输入一个URL后都发生了什么,要尽可能详细
这道题目没有所谓的完全的正确答案,这个题目可以让你在任意的一个点深入下去, 只要你对这个点是熟悉的.以下是一个大概流程: 浏览器向DNS服务器查找输入URL对应的IP地址. DNS服务器返回网站的IP ...
- Linux Kernel 4.8分支第4个候选版本发布
导读 今天,大神Linus Torvalds宣布了Linux 4.8分支的第四个候选版本,该候选版本在提供常规驱动更新.架构改善和部分KVM调整之外最大的新功能就是修复了英特尔Skylake电源管理B ...
- DevExpress控件使用小结 z
.TextEditor(barEditItem)取文本 string editValue = barEditItem1.EditValue.ToString(); //错误,返回null string ...
- UiThread DEMO
import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import android.a ...
- sqlserver能否调用webservice发送短信呢?
上班的时候突然有一个想法,sqlserver能否调用webservice发送短信呢? 经过查找资料,终于找到了解决办法,现将步骤贴到下面: (1)开启sqlserver组件功能,如果不开启这个组件功能 ...
- Matlab编程实例(2) 同期平均
%多点同期平均 close all; clear all; pi = 3.14159; Samp2=input('您需要几组信号做同期平均?') Samp1=1000 %设置采样精度 t = lins ...
- UINavigationController 操作记录
//设置字体大小 颜色 { UIColor *color = [UIColor brownColor]; UIFont * font = [UIFont systemFontOfSize:20]; N ...
- hive 传递变量的两种方式
在使用hive开发数据分析代码时,经常会遇到需要改变运行参数的情况,比如select语句中对日期字段值的设定,可能不同时间想要看不同日期的数据,这就需要能动态改变日期的值.如果开发量较大.参数多的话, ...
- notepad++汉字突然横过来了
修改notepad++,汉字突然横过来了,如图, 百度了一下,原来是因为选择的字体"@微软雅黑"前面的@符号惹的祸,改成"微软雅黑"就没事了.
- ViewPager使用笔记
1.ViewPager.setCurrentItem(position),即使已设置动画,但是没有动画效果 原因:因为ViewPager滑动之前的时间间隔太短,可以通过反射,去修改ViewPager自 ...