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. cgroup隔离的知识点

    tasks中写入的是线程号 cgroup.procs是进程号 ===================CPU隔离===================== 主机CPU核数: cat /proc/cpui ...

  2. MyBatis批量删除 多态sql,构建in语句

    <!--==========================删除==================================== -->    <delete id=&quo ...

  3. Reading or Writing to Another Processes Memory in C# z

    http://www.jarloo.com/reading-and-writing-to-memory/ Declarations [Flags] public enum ProcessAccessF ...

  4. 动画 -- ListView列表item逐个出来(从无到有)

    import android.app.ListActivity; import android.os.Bundle; import android.widget.ArrayAdapter; publi ...

  5. linux命令——磁盘命令mkdir

    一.介绍 mkdir 命令用于创建文件夹或目录(类似dos下的md命令),要求创建目录的用户在当前目录中具有写权限, 并且指定目录名不能是当前目录中已有的目录或文件名称.名称区分大小写. 二.用法及参 ...

  6. codeforces 675E Trains and Statistic 线段树+贪心统计

    分析:这个题刚看起来无从下手 但是我们可以先简化问题,首先可以固定起点i,求出i+1到n的最小距离 它可以到达的范围是[i+1,a[i]],贪心的想,我们希望换一次车可以到达的距离尽量远 即:找一个k ...

  7. Java-note-输入流

    java不像C中拥有scanf这样功能强大的函数,大多是通过定义输入输出流对象.常用的类有BufferedReader,Scanner.实例程序:一,利用 Scanner 实现从键盘读入integer ...

  8. 《Java数据结构与算法》笔记-CH1

    /** * 数据结构的特性 ************************************************************************************** ...

  9. Spark SQL概念学习系列之SQL on Spark的简介(三)

    AMPLab 将大数据分析负载分为三大类型:批量数据处理.交互式查询.实时流处理.而其中很重要的一环便是交互式查询. 大数据分析栈中需要满足用户 ad-hoc.reporting. iterative ...

  10. HDU 2425 DNA repair (AC自动机+DP)

    DNA repair Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...