Problem Statement

In a two-dimensional plane, there are $N$ towns and $M$ chests. Town $i$ is at the coordinates $(X_i,Y_i)$, and chest $i$ is at the coordinates $(P_i,Q_i)$.

Takahashi will go on a trip where he starts at the origin, visits all $N$ towns, and then returns to the origin.

It is not mandatory to visit chests, but each chest contains an accelerator. Each time he picks up an accelerator, his moving speed gets multiplied by $2$.

Takahashi's initial moving speed is $1$. Find the shortest time needed to complete the trip.

Constraints

  • $1 \leq N \leq 12$
  • $0 \leq M \leq 5$
  • $-10^9 \leq X_i,Y_i,P_i,Q_i \leq 10^9$
  • $(0,0)$, $(X_i,Y_i)$, and $(P_i,Q_i)$ are distinct.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

$N$ $M$
$X_1$ $Y_1$
$\vdots$
$X_N$ $Y_N$
$P_1$ $Q_1$
$\vdots$
$P_M$ $Q_M$

Output

Print the answer. Your output will be considered correct if the absolute or relative error from the judge's answer is at most $10^{-6}$.


Sample Input 1

2 1
1 1
0 1
1 0

Sample Output 1

2.5000000000

Here is one optimal way to complete the trip.

  • Go the distance $1$ from the origin to chest $1$ at a speed of $1$, taking a time of $1$.
  • Go the distance $1$ from chest $1$ to town $1$ at a speed of $2$, taking a time of $0.5$.
  • Go the distance $1$ from town $1$ to town $2$ at a speed of $2$, taking a time of $0.5$.
  • Go the distance $1$ from town $2$ to the origin at a speed of $2$, taking a time of $0.5$.

Sample Input 2

2 1
1 1
0 1
100 0

Sample Output 2

3.4142135624

Here is one optimal way to complete the trip.

  • Go the distance $1.41\ldots$ from the origin to town $1$ at a speed of $1$, taking a time of $1.41\ldots$.
  • Go the distance $1$ from town $1$ to town $2$ at a speed of $1$, taking a time of $1$.
  • Go the distance $1$ from town $2$ to the origin at a speed of $1$, taking a time of $1$.

Sample Input 3

1 2
4 4
1 0
0 1

Sample Output 3

4.3713203436

Here is one optimal way to complete the trip.

  • Go the distance $1$ from the origin to chest $1$ at a speed of $1$, taking a time of $1$.
  • Go the distance $1.41\ldots$ from chest $1$ to chest $2$ at a speed of $2$, taking a time of $0.707\ldots$.
  • Go the distance $5$ from chest $2$ to town $1$ at a speed of $4$, taking a time of $1.25$.
  • Go the distance $5.65\ldots$ from town $1$ to the origin at a speed of $4$, taking a time of $1.41\ldots$.

这个数据范围,考虑状压dp。

定义 \(dp_{i,j,k}\) 表示走过了集合 \(i\) 的 towns,集合 \(j\) 的 chests,现在到了 \(k\) 点的最短距离。(不妨用 \(n+i\) 表示第 \(i\) 个chests)

然后就可以枚举下一个去哪里,转移应该很简单了。就是算出两点之间的距离,除以 \(j\) 的元素个数就行了。

#include<bits/stdc++.h>
using namespace std;
const int N=13,M=6;
double dp[1<<N][1<<M][N+M],ans;
int n,m,x[N+M],y[N+M],pw[6];
long long sqr(int a)
{
return 1LL*a*a;
}
double dist(int a,int b)
{
return sqrt(sqr(x[a]-x[b])+sqr(y[a]-y[b]));
}
int popcnt(int x)
{
int cnt=0;
while(x)
cnt+=x&1,x>>=1;
return cnt;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
scanf("%d%d",&x[i],&y[i]);
for(int i=0;i<m;i++)
scanf("%d%d",&x[i+n],&y[i+n]);
for(int i=pw[0]=1;i<=5;i++)
pw[i]=pw[i-1]*2;
for(int i=0;i<(1<<N);i++)
for(int j=0;j<(1<<M);j++)
for(int k=0;k<(N+M);k++)
dp[i][j][k]=1e16;
for(int i=0;i<n;i++)
dp[1<<i][0][i]=dist(n+m,i);
for(int i=0;i<m;i++)
dp[0][1<<i][i+n]=dist(n+m,i+n);
ans=1e16;
for(int i=0;i<(1<<n);i++)
{
for(int j=0;j<(1<<m);j++)
{
int k=popcnt(j);
for(int x=0;x<n;x++)
{
if(!(i>>x&1))
continue;
for(int y=0;y<n;y++)
{
if(x==y||!(i>>y&1))
continue;
dp[i][j][x]=min(dp[i][j][x],dp[i^1<<x][j][y]+dist(x,y)/pw[k]);
}
for(int y=n;y<m+n;y++)
{
if(!(j>>(y-n)&1))
continue;
dp[i][j][x]=min(dp[i][j][x],dp[i^1<<x][j][y]+dist(x,y)/pw[k]);
}
if(i==(1<<n)-1)
ans=min(ans,dp[i][j][x]+dist(x,n+m)/pw[k]);
// printf("%d %d %d %.6lf\n",i,j,x,dp[i][j][x]) ;
}
--k;
for(int x=0;x<m;x++)
{
if(!(j>>x&1))
continue;
for(int y=0;y<n;y++)
{
if(!(i>>y&1))
continue;
dp[i][j][x+n]=min(dp[i][j][x+n],dp[i][j^1<<x][y]+dist(y,x+n)/pw[k]);
}
for(int y=0;y<m;y++)
{
if(!(j>>y&1))
continue;
dp[i][j][x+n]=min(dp[i][j][x+n],dp[i][j^1<<x][y+n]+dist(y+n,x+n)/pw[k]);
}
if(i==(1<<n)-1)
ans=min(ans,dp[i][j][x+n]+dist(x+n,n+m)/pw[k+1]);
// printf("%d %d %d %.6lf\n",i,j,x+n,dp[i][j][x+n]) ;
}
}
}
printf("%.10lf",ans);
}

[ABC274E] Booster的更多相关文章

  1. 恶意软件伪装“正规军”,撕开Booster Cleaner“画皮”下的真相

    经常使用手机浏览器阅读小说的用户都知道,在浏览器页面经常会出现一些推广游戏应用.手机清理应用等应用的弹窗广告.有时出于方便,我们也会选择直接点开这些弹窗广告进行应用下载.但这种行为并不安全,部分恶意应 ...

  2. 滴滴 App 的质量优化框架 Booster,开源了!

    一. 序 当 App 达到一定体量的时候,肯定是要考虑质量优化.有些小问题,看似只有 0.01% 触发率,但是如果发生在 DAU 过千万的产品中,就很严重了. 滴滴这个独角兽的 DAU 早已过千万,自 ...

  3. 滴滴Booster移动APP质量优化框架 学习之旅 三

    推荐阅读: 滴滴Booster移动App质量优化框架-学习之旅 一 Android 模块Api化演练 不一样视角的Glide剖析(一) 滴滴Booster移动App质量优化框架-学习之旅 二对重复资源 ...

  4. 滴滴Booster移动APP质量优化框架 学习之旅 二

    推荐阅读: 滴滴Booster移动App质量优化框架-学习之旅 一 Android 模块Api化演练 不一样视角的Glide剖析(一) 续写滴滴Booster移动APP质量优化框架学习之旅,上篇文章分 ...

  5. 滴滴Booster移动APP质量优化框架 学习之旅

    推荐阅读: 滴滴Booster移动App质量优化框架-学习之旅 一 Android 模块Api化演练 不一样视角的Glide剖析(一) 一.Booster简介 Booster是滴滴最近开源一个的移动应 ...

  6. IObit Driver Booster 无法更新驱动的解决办法

    IObit Driver Booster 无法更新驱动的解决办法:依次打开软件中的 菜单-设置-网络-自定义代理设置-主机:填入210.101.131.231 端口:8080 最后点确定完成. 注意! ...

  7. 对xgboost中dump_model生成的booster进行解析

    xgboost原生包中有一个dump_model方法,这个方法能帮助我们看到基分类器的决策树如何选择特征进行分裂节点的,使用的基分类器有两个特点: 二叉树: 特征可以重复选择,来切分当前节点所含的数据 ...

  8. angular2系列教程(六)两种pipe:函数式编程与面向对象编程

    今天,我们要讲的是angualr2的pipe这个知识点. 例子

  9. Mac 软件篇

    对于美好事务的追求无论何时都不算晚. ** 文章内容来着我整理的fetool,以下内容可能更新不及时 ** Mac 下的软件那么多,又是免费又是付费,应该怎么选呢?我来分享下我的推荐列表,推荐的优先级 ...

  10. 【软件工具】Driver Booster3永久激活法

    原作者網址:erik2041999 (YouTube) 1.安装Driver Booster3 (档案已附) 2.使用此启动码0187E-B9764-4D9FA-211B3断网启动 3.保持断网状态并 ...

随机推荐

  1. CF1787E The Harmonization of XOR 题解

    CF1787E The Harmonization of XOR 题目大意 给定 \(n\) 个数 \([1, 2, 3, \cdots, n]\) 和两个正整数 \(k\) 和 \(x\). 将这些 ...

  2. 数据可视化【原创】vue+arcgis+threejs 实现海量建筑物房屋渲染,性能优化

    本文适合对vue,arcgis4.x,threejs,ES6较熟悉的人群食用. 先报备一下版本号 "vue": "^2.6.11" "@arcgis/ ...

  3. api接口对接如何实现,php如何对接api

    API接口对接是现代软件开发中不可或缺的一部分,它允许不同的应用程序之间进行数据交换和服务调用.在PHP中,可以使用多种方式实现API接口的对接,包括基于HTTP协议的传统方法以及现代的API客户端库 ...

  4. 杰哥教你面试之一百问系列:java中高级多线程concurrent的使用

    目录 问题1:什么是ConcurrentHashMap?它与HashMap的区别是什么? 问题2:什么是CopyOnWriteArrayList?它适用于什么样的场景? 问题3:什么是Blocking ...

  5. 「codeforces - 1720」

    壹 最近 cq 情况很急急,昨天出去排核酸整了两个半小时,十分无语.提前放假自然是一大好事,但是一个人在家也蛮无聊.不要再涨体重了为好,这一年间他妈 delta 了 10 kilos,算了下 BMI ...

  6. R3300L, Q7 ATV Android9固件

    R3300L, Q7 ATV Android9固件 固件来源 https://www.znds.com/tv-1239603-1-1.html 之前在恩山上发布过1080p安卓6固件 https:// ...

  7. 【RocketMQ】Dledger模式下的日志复制

    RocketMQ在开启Dledger时,使用DLedgerCommitLog,其他情况使用的是CommitLog来管理消息的存储.在Dledger模式下,消息写入时Leader节点还需要将消息转发给F ...

  8. Docker系列——介绍、安装、镜像、容器、docker容器与镜像、数据卷、Dockerfile、docker 配置pycharm连接

    目录 1 Docker 介绍 1.1 简介 1.2 Docker平台介绍 1.3 为什么使用Docker 2 Docker 整体结构(了解) 2.1 Docker引擎介绍 (Docker Engine ...

  9. 成本阶问题:财务模块axcr004合计金额检核表第18行合计金额与明细差异过大问题处理?

    财务模块axcr004合计金额检核表第18行合计金额与明细差异过大问题处理? 可能原因:生产开立工单时元件未建在生产料件BOM明细中,导致成本阶没有算到,需要手动更改成本阶. 公式: 处理办法:修改成 ...

  10. 【Mac2021版Intel芯片下载】 - Intel芯片推荐安装

    [Mac2021版Intel芯片下载] - Intel芯片推荐安装 往下拉有安装图文教程一.下载提示1请点击图标进行下载 ●每个软件下方均标注了该软件的用途,请注意查看: ●如果点击无反应,请换一个浏 ...