POJ 3311 Hie with the Pie(状态压缩DP)

Win11 24H2共享访问被禁?深入聊聊SMB签名和‘不安全的来宾登录’那点事 本文深入解析Win11 24H2共享访问故障,探讨SMB签名的安全机制与‘不安全的来宾登录’问题。提供从注册表修改到组策略配置的多层次解决方案,特别针对家庭网络和打印机共享场景给出实用建议,帮助用户在安全与便利之间找到平衡。 阅读详情
Hie with the Pie
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 6776 Accepted: 3652

Description

The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortunately, due to cutbacks, they can afford to hire only one driver to do the deliveries. He will wait for 1 or more (up to 10) orders to be processed before he starts any deliveries. Needless to say, he would like to take the shortest route in delivering these goodies and returning to the pizzeria, even if it means passing the same location(s) or the pizzeria more than once on the way. He has commissioned you to write a program to help him.

Input

Input will consist of multiple test cases. The first line will contain a single integer n indicating the number of orders to deliver, where 1 ≤ n ≤ 10. After this will be n + 1 lines each containing n + 1 integers indicating the times to travel between the pizzeria (numbered 0) and the n locations (numbers 1 to n). Thejth value on the ith line indicates the time to go directly from location i to location j without visiting any other locations along the way. Note that there may be quicker ways to go from i to j via other locations, due to different speed limits, traffic lights, etc. Also, the time values may not be symmetric, i.e., the time to go directly from location i to j may not be the same as the time to go directly from location j to i. An input value of n = 0 will terminate input.

Output

For each test case, you should output a single number indicating the minimum time to deliver all of the pizzas and return to the pizzeria.

Sample Input

3
0 1 10 10
1 0 1 2
10 1 0 10
10 2 10 0
0

Sample Output

8

Source

East Central North America 2006


大体题意:外卖员要去送比萨,给出外卖店与所有顾客两两之间的距离,求将所有比萨送出并返回比萨店的最短时间。

大体思路:首先用Floyd求一遍最短距离。因为顾客数很少,可以用一个二进制串来表示是否给第i名顾客送过(0表示没有,1表示有)。我们用DP(S,i)表示“在给第j位顾客送过比萨后状态为S”,那么DP的边界就为DP(1 << i,  i)= dis[0][i],即只给第i位顾客送去比萨的最短距离为从比萨店到该顾客的距离。状态转移如下:如果状态S中有第i位顾客,那么给第i位顾客送餐的最短距离为(先给第j位顾客送(这个状态要有j不能有i),再从j到i的最短距离,相当于一个中转)。最后的答案就是MIN{ DP( (1 << n) - 1, i) + dis[i][0]}。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int INF = 1e9 + 10;
const int maxn = 15;
int dp[1<<11][maxn], dis[maxn][maxn];
int main()
{
    int n;
    while(scanf("%d",&n) == 1 && n) {
        for (int i = 0; i <= n; i++)
          for (int j = 0; j <= n; j++)
             scanf("%d",&dis[i][j]);
             
        //Floyd
        for (int k = 0; k <= n; k++)
          for (int i = 0; i <= n; i++)
            for (int j = 0; j <= n; j++)
               dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
               
        //DP求解
        for (int S = 1; S < (1<<n); S++) {
            for (int i = 1; i <= n; i++) if (S & (1<<(i-1))) { //如果状态中有第i名顾客
                if (S == (1<<(i-1))) dp[S][i] = dis[0][i]; //DP边界,如果只给第i名顾客送,那么距离就是起点到这位顾客的距离。
                else {
                    dp[S][i] = INF;
                    for (int j = 1; j <= n; j++) if (S & (1<<(j-1))) { //先给j送,再从j到i
                        if (j == i) continue;
                        dp[S][i] = min(dp[S][i], dp[S^(1<<(i-1))][j] + dis[j][i]);
                    }
                }
            }
        }
        
        int mi = INF;
        for (int i = 1; i <= n; i++) {
            mi = min(mi, dp[(1<<n)-1][i] + dis[i][0]);
        }
        printf("%d\n",mi);
    }

}

 

Multisim 14.0实战:从零搭建可调幅多波形信号发生器(附仿真文件) 本文详细介绍了如何在Multisim 14.0中从零搭建一个可调幅多波形信号发生器,涵盖方波、三角波和正弦波的生成原理与实现步骤。通过核心电路架构解析、关键参数设计及Multisim实战操作,帮助电子工程学习者和硬件工程师掌握信号发生器的设计与调试技巧,并提供仿真文件供实践验证。 阅读详情

相关推荐

压电传感器信号放大难题?用运放设计电荷放大器的5个关键步骤

本文详细解析了压电传感器信号放大难题,并提供了用运放设计电荷放大器的5个关键步骤。从电压放大到电荷放大的范式转换,到运放选型、反馈网络设计、PCB布局及频响特性验证,帮助工程师解决工业自动化中的信号衰减问题,提升测量精度和稳定性。

weixin_27303545的博客 447

POJ 3311 Hie with the Pie(Floyd+状态压缩DP)

//Floyd + 状态压缩DP //题意是有N个城市(1~N)和一个PIZZA店(0),要求一条回路,从0出发,又回到0,而且距离最短 //也就是TSP(旅行商)问题,首先不难想到用FLOYD先求出任意2点的距离dis[i][j] //接着枚举所有状态,用11位二进制表示10个城市和pizza店,1表示经过,0表示没有经过 //定义状态DP(S,i)表示在S状态下,到达城市I的最优值 //接着状态转移方程:DP(S,i) = min{DP(S^(1 #define INF 100000000

Czy 5237

DTS中video-interfaces接口详解

视频数据管道通常由外部设备组成,例如通过I2C、SPI或UART总线控制的摄像机传感器,以及SoC内部IP块(包括视频DMA引擎和视频数据处理器)。 SoC内部块由DT节点描述,与其他SoC块放置方式类似。外部设备表示为它们各自总线控制器节点的子节点,例如I2C。 所有视频设备上的数据接口都由它们的子“port”节点描述。端口的配置取决于参与数据传输的其他设备,并由“endpoint”子节...

龙图腾的博客 9008

POJ3311 Hie with the Pie floyd+状态压缩DP

今年天津网赛就有一道这样的类似题目,当时有思路感觉和TSP问题很像,就是想不出来怎么做,挺可惜的。因此趁着这段时间搞一下状态压缩DP 状态转移方程 dp[s][i] =min{dp[s][i],dp[s'][j]+dis[j][i]} dp[s][i]表示到达状态s时位于i位置的最小耗费,dis[j][i]表示两点之间的最短路 在DP之前要用floyd预处理一下求出每两个点之间的最短距离。

802

Drools vs URule:5个真实项目场景告诉你如何选择开源规则引擎

本文通过电商风控、物流计费、会员体系、保险定价和物联网告警五个真实项目场景,深度对比了Drools与URule两款开源规则引擎。分析了两者在规则复杂度、性能表现、开发运维及适用场景上的核心差异,为技术选型提供基于实战的决策指南。

k6l7m8n9的博客 944

【实战指南】WinPE环境下360系统急救箱的病毒查杀全流程解析

本文详细解析了在WinPE环境下使用360系统急救箱进行病毒查杀的全流程。从制作WinPE启动盘到进入PE环境,再到360急救箱的深度使用和系统修复,提供了实用技巧和常见问题解决方案,帮助用户高效清除顽固病毒。

weixin_28568819的博客 535

POJ 3311 Hie with the Pie //状态压缩DP

TSP,可以用状态压缩做,记得先用FLOYED处理 #include #include #include using namespace std; int n; int map[12][12]; int dp[(1 << 11) - 1][11]; int mai

hqd_acm的专栏 855

Tesseract OCR 字库训练教程:提高识别率进阶版

通过 Tesseract 字库训练,你可以提高 OCR 对特定文本或字体的识别能力。训练过程包括准备训练数据、生成标签文件、运行训练工具,以及将训练结果集成到实际项目中。虽然训练过程需要一些时间和精力,但对于需要高精度文本识别的场景来说,字库训练是非常有效的提升识别率的方法。

小蜗牛的珍贵百宝箱 1866

【POJ3311】Hie with the Pie(状态压缩DP)

Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5031   Accepted: 2678 Description The Pizazz Pizzeria prides itself in delivering pizzas to

ACM之路 553

【路径规划】Theta_star算法机器人栅格地图最短路径规划【含Matlab源码 2618期】

Theta_star算法机器人栅格地图最短路径规划 完整的代码,方可运行;可提供运行操作视频!适合小白!

订阅付费专栏Matlab(奶茶价版),可赠送奶茶价版付费专栏指定代码1份; 363

科研绘图系列:R语言绘制宏基因组分析的可视化图形(network & barplot & heatmap)

科研绘图系列:R语言多图形组合(network & barplot & heatmap)

专注生信领域 644

【POJ 3311】 Hie with the Pie 状态压缩DP

Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortunately, due to cutbacks, they can afford to hire only one driver to do the deliveries. ...

yyying2016的博客 254

【30】软考软件设计师——UML类图与用例图满分精讲|下午第3题常考核心

本文是《软件设计师·50讲通关|从零基础到工程师职称》专栏第30篇,聚焦**模块四:应用技术(下午题)第3道高频大题**,UML建模是历年下午必考核心,单题分值稳定10~12分。全文深度拆解两大核心UML图表:**类图**与**用例图**,超详细讲解类图三层结构、可见性修饰符、五大核心关系(泛化/关联/依赖/聚合/组合)的判定标准与绘图规范;吃透用例图参与者、系统边界、三大关系(包含/扩展/泛化)的底层逻辑,搭配独家**关系秒杀口诀、标准绘图模板、真题改错技巧**;全文适配补图、判断关系、分析场景、纠错优化

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 572

poj 3311 Hie with the Pie(状态压缩dp)

Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortunately, due to cutbacks, they can afford to hire only one driver to do the del...

dielucuan8830的博客 118

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

poj3311 Hie with the Pie(状态压缩dp)

poj3311分析首先用弗洛伊德算法求一下两点之间的最短路,然后枚举每一个状态,枚举两个经过的但是不同的点,进行初始化,或者是状态转移。dp[s][i]表示状态为s,到了i点。题目http://poj.org/problem?id=3311代码#include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #inclu

天道酬勤 430

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

POJ 3311 Hie with the Pie 状态压缩DP

题意:求从0点走到所有点又走回来的最短距离 该题又很多做法,我用的是弗洛伊德+状态压缩 先遍历所有点,求出两点间最短的距离,而后用状态压缩表示该点是否走过,(1 附AC代码 #include #include int map[12][12]; int dp[(1<<12)+1][12]; int min1(int a,int b) { if(a<b) return a; return

诺诺罗亚 611

POJ 3311 Hie with the Pie 状态压缩DP+floyd

Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8106   Accepted: 4411 Description The Pizazz Pizzeria prides itself in delivering pizzas t

J. Cole 317

POJ3311 Hie with the Pie floyd+状态压缩DP

POJ3311 Hie with the Pie floyd+状态压缩DP

htrdchh的博客 225

POJ 3311 Hie with the Pie(状态压缩DP)

dp[s][v] 表示从v出发 访问剩余还未访问过的集合s。 这里的集合s不是一个普通的整数   对于集合s我们可以把每一个元素的选取与否对应到一个二进制位里面  从而把状态压缩成一个整数,大大简化了计算和维护。 /* qq:1239198605 ctgu_yyf */ #include &lt;iostream&gt; #include &lt;cstdio&gt;...

k_koris的博客 210

POJ3311 Hie with the Pie(状态压缩dp)

题目要求,从0出发,必须经过N个点,然后回到0点。 每两个点之间花费的时间不同,i到j和j到i也不同,求最短时间。 1先用floyd算法求出两点之间最短路径 2递归方程 dp[j][i]=min(dp[j][i],dp[k][i&(~(1   j表示终点 i为二进制表示状态 1表示经过 0表示不经过 把所有可能的路径排列出来 找最小值   i&(~(1   k表示中转点 先从去掉一个经

Unknown 1299

POJ 3311 Hie with the Pie(状态压缩dp)

题目分析 这道题需要求从0点出发(披萨店)经过其他所有点,并且回到原点的最短距离,因为点数不多最多10个点,很明显是一个TSP问题,并且可以用状态压缩dp进行求解。 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int INF = 0

你真的介意真的在乎真的想要真的渴望的话你一定能够做到 291

POJ 3311 Hie with the Pie (状态压缩DP)

题目大意:规定原点为0,给出n,表示除了原点外还有n个点。然后给出一个矩阵dis[][],dis[i][j]表示i到j的距离。要求每个点都走过一次,并且最终回到原点,求最短路。其中点是可以重复走的。1 这是经典的旅行商问题(TSP),入门状态压缩DP,其中n的取值是个标志。 由于n 定义状态dp[state][k]表示在状态state,且最终停留在k点时的最短路。则有转移方程: dp[s

GentleH's 514

POJ 3311 Hie with the Pie -- TSP 状态压缩dp

/* http://poj.org/problem?id=3311 Hie with the Pie 旅行商问题,状态压缩的dp */ #include #include #include #include #include #include using namespace std; #define CLR(c,v) memset(c,v,sizeof(c)) template

生命有一种绝对 854
上一篇: POJ 2187 Beauty Contest(凸包)
下一篇: UVa 11584 Partitioning by Palindromes(DP)
Interstellar_
博客等级 码龄10年 8粉丝 121原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值