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的更多相关文章

  1. Educational Codeforces Round 13 E. Another Sith Tournament 状压dp

    E. Another Sith Tournament 题目连接: http://www.codeforces.com/contest/678/problem/E Description The rul ...

  2. Codeforces 1225G - To Make 1(bitset+状压 dp+找性质)

    Codeforces 题目传送门 & 洛谷题目传送门 还是做题做太少了啊--碰到这种题一点感觉都没有-- 首先我们来证明一件事情,那就是存在一种合并方式 \(\Leftrightarrow\) ...

  3. Problem Arrangement ZOJ - 3777(状压dp + 期望)

    ZOJ - 3777 就是一个入门状压dp期望 dp[i][j] 当前状态为i,分数为j时的情况数然后看代码 有注释 #include <iostream> #include <cs ...

  4. K - Painful Bases 状压dp

    Painful Bases LightOJ - 1021 这个题目一开始看,感觉有点像数位dp,但是因为是最多有16进制,因为限制了每一个数字都不同最多就有16个数. 所以可以用状压dp,看网上题解是 ...

  5. Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞

    Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1006 ...

  6. Codeforces Gym 100610 Problem A. Alien Communication Masterclass 构造

    Problem A. Alien Communication Masterclass Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codefo ...

  7. Codeforces Gym 100610 Problem E. Explicit Formula 水题

    Problem E. Explicit Formula Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...

  8. CF1103D Codeforces Round #534 (Div. 1) Professional layer 状压 DP

    题目传送门 https://codeforces.com/contest/1103/problem/D 题解 失去信仰的低水平选手的看题解的心路历程. 一开始看题目以为是选出一些数,每个数可以除掉一个 ...

  9. 【Codeforces】Gym 101173B Bipartite Blanket 霍尔定理+状压DP

    题意 给一张$n\times m$二分图,带点权,问有多少完美匹配子集满足权值和大于等于$t$ 这里有一个结论:对于二分图$\mathbb{A}$和$\mathbb{B}$集合,如果子集$A \in ...

随机推荐

  1. 漂亮灵活设置的jquery通知提示插件toastr

    toastr是一款非常棒的基于jquery库的非阻塞通知提示插件,toastr可设定四种通知模式:成功,出错,警告,提示,而提示窗口的位置,动画效果都可以通过能数来设置,在官方站可以通过勾选参数来生成 ...

  2. MyBatis 如何接收参数

    MyBatis的mapper接口不需要自己实现,框架会自动帮我们实现,到时候直接调用就可以了.定义的mapper接口中的方法可以有多个参数吗?答案是肯定.在Ibatis时代是自己通过代码实现如何调用x ...

  3. [转] C#实现自动化Log日志

    qing2005原文地址 C#实现自动化Log日志 在开发项目的时候,我们不免要使用Log记录日志,使用最多的是Log4Net和EntLib Log,在需要记录日志的代码处加入log.Write(日志 ...

  4. String.Format格式说明

    原文地址:http://www.cnblogs.com/tuyile006/archive/2006/07/13/449884.aspx C#格式化数值结果表 字符 说明 示例 输出 C 货币 str ...

  5. 给Webkit内核的浏览器控件增加互交功能

    转载请说明出处,谢谢~~ 昨天封装了基于webkit的wke浏览器内核,做成了duilib的浏览器控件,实现了浏览功能,但是单单的浏览功能还不满足需求,在我的仿酷狗项目中乐库的功能需要与浏览器互交. ...

  6. 通过库函数API和C代码中嵌入汇编代码剖析系统调用的工作机制

    作者:吴乐 山东师范大学<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 本次实验的主要内容就是分别采用A ...

  7. Centos yum源更新为阿里云

    阿里云镜像网址 http://mirrors.aliyun.com/   更新步骤 1.备份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d ...

  8. SSH无法连接服务器

    服务器版本如下: @kelWEB4:/etc# lsb_release -a LSB Version: :core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd ...

  9. bzoj 3675 [Apio2014]序列分割(斜率DP)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3675 [题意] 将n个数的序列分割k次,每次的利益为分割后两部分数值和的积,求最大利益 ...

  10. Tkinter教程之Text篇(3)

    本文转载自:http://blog.csdn.net/jcodeer/article/details/1811348 '''Tkinter教程之Text篇(3)''''''14.自定义tag的两个内置 ...