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. Oracle 课程一之Oracle体系结构

    课程目标 •理解ORACLE数据库体系架构—内存结构和进程 •理解SQL在数据库中的运作流程 •理解UNDO&REDO原理 •理解commit原理   1.Oracle数据库概述 •数据库:物 ...

  2. 用defy来潜水最终还是挂了........

    defy526是6级,,不过好像这次我用来潜过去不足2米还是挂掉了... 国际通用的防水级别认证体系: IPX-0 没有防水保护 IPX-1 设备在正常操作状态下,可以提供相当于3-5毫米/分钟降雨的 ...

  3. java web 学习十四(JSP原理)

    一.什么是JSP? JSP全称是Java Server Pages,它和servle技术一样,都是SUN公司定义的一种用于开发动态web资源的技术. JSP这门技术的最大的特点在于,写jsp就像在写h ...

  4. 使ViewFlipper中的WebView实现手势效果

    使ViewFlipper中的WebView实现手势效果   今天写Blog阅读器的时候遇到了这个问题,把它分享给大家,让同样是新手们少走冤枉路始初写这个功能的时候,用过了好多方法,也耗了不少时间去研究 ...

  5. HDU 5750 Dertouzos 简单数学

    感悟:这又是zimpha巨出的一场题,然后04成功fst(也就是这题) 实际上还是too young,要努力增加姿势, 分析:直接枚举这些数不好枚举,换一个角度,枚举x*d,也就是d的另一个乘数是多少 ...

  6. 【剑指offer 面试题14】调整数组顺序使奇数位于偶数前面

    思路: 头尾指针,向中间遍历,依据条件交换元素. #include <iostream> using namespace std; void reOrder(int *pData, uns ...

  7. 约瑟夫环是一个数学的应用问题:已知n个人(以编号1,2,3...n分别表示)围坐在一张圆桌周围。从编号为k的人开始报数,数到m的那个人出列;他的下一个人又从1开始报数,数到m的那个人又出列;依此规律重复下去,直到圆桌周围的人全部出列。

    以数组的方法: public static void main(String[] args) {        final int n = 10;          final int k = 1;  ...

  8. 使用DDMS测试安卓手机APP的性能(android)

    安装/配置: 通过另外一个工具也可以测试手机客户端APP的性能,这就是android开发包中的DDMS工具(Dalvik Debug Monitor Service),先来说一下android开发包的 ...

  9. (三)相遇射线的3D碰撞盒

    序 在2D游戏中,我们知道处理碰撞时,需要设置精灵遮罩图.同样,进入3D,处理碰撞时需要3D模型作为“遮罩图”. 索尼克 飞檐走壁   目的 (1)处理模型间的碰撞问题         (2)获取鼠标 ...

  10. Canvas入门(3):图像处理和绘制文字

    来源:http://www.ido321.com/997.html 一.图像处理(非特别说明,所有结果均来自最新版Google) 在HTML 5中,不仅可以使用Canvas API绘制图形,也可以用于 ...