Gym-100648B: Hie with the Pie(状态DP)
题意:外卖员开始在0号节点,有N个人点了外卖,(N<=10),现在告诉两两间距离,问怎么配送,使得每个人的外卖都送外,然后回到0号点的总时间最短,注意,同一个点可以多次经过。
思路:TSP问题(货郎担问题),可以通过状态DP解决小数据问题。 先floyd求一下两两最近距离,然后DP;
dp[i][j]表示经过状态为i,当前在j号节点是最小耗时。 ans=min(dp[S][i]+dis[i][0]);
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
int dp[maxn][],dis[][],N,cnt,ans,S;
int Laxt[maxn],Next[maxn],To[maxn],Len[maxn];
void floyd()
{
rep(k,,N)
rep(i,,N)
rep(j,,N) if(dis[i][j]>dis[i][k]+dis[k][j])
dis[i][j]=dis[i][k]+dis[k][j];
}
void solve()
{
S=(<<(N+))-;
dp[][]=;
rep(i,,S){
rep(k,,N)
rep(j,,N){
dp[i|(<<j)][j]=min(dp[i][k]+dis[k][j],dp[i|(<<j)][j]);
}
}
}
int main()
{
while(~scanf("%d",&N)&&N){
memset(dp,,sizeof(dp));
rep(i,,N) Laxt[i]=; cnt=;
rep(i,,N)
rep(j,,N)
scanf("%d",&dis[i][j]);
floyd();
solve();
ans=dp[S][]+dis[][];
rep(i,,N) ans=min(ans,dp[S][i]+dis[i][]);
printf("%d\n",ans);
}
return ;
}
Gym-100648B: Hie with the Pie(状态DP)的更多相关文章
- PKU 3311 Hie with the Pie 状态DP
Floyd + 状态DP Watashi的板子 #include <cstdio> #include <cstring> #include <iostream> # ...
- poj3311 Hie with the Pie (状态压缩dp,旅行商)
Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3160 Accepted: 1613 ...
- POJ 3311 Hie with the Pie(DP状态压缩+最短路径)
题目链接:http://poj.org/problem?id=3311 题目大意:一个送披萨的,每次送外卖不超过10个地方,给你这些地方之间的时间,求送完外卖回到店里的总时间最小. Sample In ...
- POJ 3311 Hie with the Pie(Floyd+状态压缩DP)
题是看了这位的博客之后理解的,只不过我是又加了点简单的注释. 链接:http://blog.csdn.net/chinaczy/article/details/5890768 我还加了一些注释代码,对 ...
- poj 3311 Hie with the Pie dp+状压
Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4671 Accepted: 2471 ...
- POJ3311 Hie with the Pie 【状压dp/TSP问题】
题目链接:http://poj.org/problem?id=3311 Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total ...
- POJ 3311 Hie with the Pie 最短路+状压DP
Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11243 Accepted: 5963 ...
- POJ 3311 Hie with the Pie(状压DP + Floyd)
题目链接:http://poj.org/problem?id=3311 Description The Pizazz Pizzeria prides itself in delivering pizz ...
- poj 3311 Hie with the Pie
floyd,旅游问题每个点都要到,可重复,最后回来,dp http://poj.org/problem?id=3311 Hie with the Pie Time Limit: 2000MS Me ...
随机推荐
- CTS/APIO2019 游记
已经记不得是第几天了就按顺序编号好了. 一 久违的到了北京,上次来北京还是在去年CTSC和APIO的时候.回想起来,这一年发生了很多事情啊. 下午是THUPC的试机赛,我和假雪菜.嘿嘿嘿两个神仙队友过 ...
- DevOps-ISC,CSS,Prometheus,Ansible ,Terraform,zabbix
https://www.terraform.io/ Terraform Use Infrastructure as Code to provision and manage any cloud, in ...
- JSON学习(二)
首先,定义一个实体类Person: import com.fasterxml.jackson.annotation.JsonFormat; import java.util.Date; public ...
- 快速排序(Quick Sort)C语言
已知数组 src 如下: [5, 3, 7, 6, 4, 1, 0, 2, 9, 10, 8] 快速排序1 在数组 src[low, high] 中,取 src[low] 作为 关键字(key) . ...
- Python列表添加元素
Python列表添加元素 1.appent() 在列表尾部添加一个元素 >>>my_list.append("append方法") >>>my_ ...
- 下载并使用MNIST数据集
TensorFlow提供了一个库,可以直接用来自动下载与安装MNIST. MNIST里包含3个数据集:第一个是训练数据集(mnist.train.images),另外两个分别是测试数据集(mnist. ...
- C# 练习题 有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?
题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?程序分析: 兔子的规律为数列1,1,2,3,5,8, ...
- 关于SQL中SELECT *(星号)的危害论
听闻有许多人是禁止开发人员在SQL中使用SELECT *的,这里翻译一下StackOverflow的一篇提问,个人认为相当客观 [SELECT *]危害主要有以下几点: 给数据消费者传数据的低效.当你 ...
- Python中的 x+=x 与 x = x + x的区别
对于Python中的可变数据类型(列表,字典)来说,+= 和 ..=..+..是不同的 加等是直接在变量的值上面进行操作,会修改了原来变量的值 先等后加会重新分配一个内存空间,不会再原有的变量值上面进 ...
- Redis安装、主从配置及两种高可用集群搭建
Redis安装.主从配置及两种高可用集群搭建 一. 准备 Kali Linux虚拟机 三台:192.168.154.129.192.168.154.130.192.168.154 ...