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 ;
}

最新文章

  1. php-cgi not found
  2. [Git]在Windows上安装Git
  3. winform学习之----打开文件对话框并将文件内容放入文本框
  4. Codeforces 741B:Arpa&#39;s weak amphitheater and Mehrdad&#39;s valuable Hoses(01背包+并查集)
  5. XenServer6.2详细安装步骤
  6. greatis很不错,出售源代码
  7. 你是否也在学习ES6 Promise时遇到过这个问题?
  8. 学习目标或者作业的制定(SMART原则)
  9. 拓扑排序&amp;关键路径
  10. JToken和BsonValue对象的相互转换
  11. 滑动时候报错:Unable to preventDefault inside passive event listener, 移动端滑动性能优化
  12. java内部类和异常类的概念
  13. mysql数据库全备和全备还原(使用Xtrabackup)
  14. 【sql基础】按照名字分组查询时间最早的一条记录
  15. [Database.System.Concepts(6th.Edition.2010)].Abraham.Silberschatz. Ch8学习笔记
  16. MongoDB的启动与停止(一)
  17. php腾讯面试题(转)
  18. 2019.01.20 bzoj3999: [TJOI2015]旅游(树链剖分)
  19. jsp二(指令)
  20. 命令:mktemp

热门文章

  1. 一天一个Java基础——反射
  2. MySQL基础之第7章 索引
  3. SQL 2005 日志损坏的恢复方法
  4. ural 1297(后缀数组+RMQ)
  5. Dapper.net 在Parameterized时对于String的扩展(转)
  6. hdu1722 bjfu1258 辗转相除法
  7. 【剑指offer 面试题16】反转链表
  8. 在eclipse.ini中指定jdk的方式
  9. Spring学习笔记(二)Spring基础AOP、IOC
  10. Hbase笔记——RowKey设计