题目链接:http://poj.org/problem?id=3311

题目大意:一个送披萨的,每次送外卖不超过10个地方,给你这些地方之间的时间,求送完外卖回到店里的总时间最小。

Sample Input

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

Sample Output

8

分析:dp[i][j]:表示在i状态(用二进制表示城市有没有经过)时最后到达j城市的最小时间,转移方程:dp[i][j]=min(dp[i][k]+d[k][j],dp[i][j])  d[k][j]是k城市到j城市的最短距离,显然要先用flody处理一下。

代码如下:
 # include<stdio.h>
# include<string.h>
int map[][],n,m,dp[<<][];
const int INF = <<; int min(int a,int b){
return a<b ?a :b;
} void flody(){
int i,j,k;
for(k=; k<=n; k++)
for(i=; i<n; i++)
for(j=; j<=n; j++){
if(map[i][k] + map[k][j] < map[i][j])
map[i][j] = map[i][k] + map[k][j];
}
}
int main(){
int i,j,k;
while(scanf("%d",&n) && n){
for(i=; i<=n; i++)
for(j=; j<=n; j++)
scanf("%d",&map[i][j]);
flody();
int ans = INF;
for(i=; i<(<<n); i++)
for(j=; j<=n; j++)
if(i==(<<(j-)))
dp[i][j] = map[][j];
else
if(i & (<<(j-))){
dp[i][j] = INF;
for(k=; k<=n; k++)
if(k!=j && (i & (<<(k-))))
dp[i][j] = min(dp[i^(<<(j-))][k] + map[k][j],dp[i][j]);
}
for(i=; i<=n; i++)
ans = min(ans, dp[(<<n)-][i]+map[i][]);
printf("%d\n",ans);
}
return ;
}
 

POJ 3311 Hie with the Pie(DP状态压缩+最短路径)的更多相关文章

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

    题是看了这位的博客之后理解的,只不过我是又加了点简单的注释. 链接:http://blog.csdn.net/chinaczy/article/details/5890768 我还加了一些注释代码,对 ...

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

    Description The Pizazz Pizzeria prides itself or more (up to ) orders to be processed before he star ...

  3. poj 3311 Hie with the Pie dp+状压

    Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4671   Accepted: 2471 ...

  4. poj 3311 Hie with the Pie

    floyd,旅游问题每个点都要到,可重复,最后回来,dp http://poj.org/problem?id=3311 Hie with the Pie Time Limit: 2000MS   Me ...

  5. poj 3311 Hie with the Pie (TSP问题)

    Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4491   Accepted: 2376 ...

  6. POJ 3311 Hie with the Pie(状压DP + Floyd)

    题目链接:http://poj.org/problem?id=3311 Description The Pizazz Pizzeria prides itself in delivering pizz ...

  7. POJ 3311 Hie with the Pie floyd+状压DP

    链接:http://poj.org/problem?id=3311 题意:有N个地点和一个出发点(N<=10),给出全部地点两两之间的距离,问从出发点出发,走遍全部地点再回到出发点的最短距离是多 ...

  8. POJ 3311 Hie with the Pie 最短路+状压DP

    Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11243   Accepted: 5963 ...

  9. POJ 3311 Hie with the Pie (BFS+最短路+状态压缩)

    题意:类似于TSP问题,只是每个点可以走多次,求回到起点的最短距离(起点为点0). 分析:状态压缩,先预处理各点之间的最短路,然后sum[i][buff]表示在i点,状态为buff时所耗时...... ...

  10. [poj3311]Hie with the Pie(Floyd+状态压缩DP)

    题意:tsp问题,经过图中所有的点并回到原点的最短距离. 解题关键:floyd+状态压缩dp,注意floyd时k必须在最外层 转移方程:$dp[S][i] = \min (dp[S \wedge (1 ...

随机推荐

  1. 北京Uber优步司机奖励政策(2月6日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  2. windows下svn+apache搭建svn服务器

    使用软件: apache_2.0.55-win32-x86-no_ssl.msi Setup-Subversion-1.5.3.msi TortoiseSVN-1.5.10.16879-win32-s ...

  3. oc学习之路----scrollView的代理模式

    右图是OC里面scrollView的代理的描述,从这里可以开出来,任何对象都可以作为scorllView的代理对象只要实现了UIScrollViewDelegate这个协议,为什么呢,原因要追究到UI ...

  4. NSThread常见方法

    // CACurrentMediaTime:获取绝对时间:从新世纪到现在的绝对时间,常用来计算耗时操作的时间差(结束时间 - 开始时间) double start = CACurrentMediaTi ...

  5. ASP.NET MVC- 布署

    IIS6.0 1. 安装Microsoft .net FrameWork 4.0安装包; 2. 安装ASP.NET MVC 3; 3. 设置“Web扩展服务”中的“ASP.NET v4.0.0.303 ...

  6. CCS样式表小结

    CSS(Cascading Style Sheet,叠层样式表),作用是美化HTML网页. /*注释区域*/    此为注释语法 一.样式表 (一)样式表的分类 1.内联样式表 和HTML联合显示,控 ...

  7. iOS 检测网络状态

    一般有两种方式,都是第三方的框架,轮子嘛,能用就先用着,后面再优化. 一:Reachability 1.首先在AppDelegate.h添加头文件"Reachability.h", ...

  8. CAS分析——Core

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...

  9. android 文件读取(assets、raw)

    需要注意的是,来自Resources和Assets 中的文件只可以读取而不能进行写的操作. assets文件夹里面的文件都是保持原始的文件格式,需要用AssetManager以字节流的形式读取文件. ...

  10. HDU 4465 - Candy(概率与数学优化)

    2012成都Regional的B题,花了一个小时推出了式子,但是搞了好久发现都控制不了精度,后来突然想到组合数可以用log优化,改了之后就AC了 比较水的概率题 #include <stdio. ...