题目链接: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. Fibonacci数列小程序

    Fibonacci数列小程序 问题分析:Fibonacci数列特征是前两项数均为1,从第三项起,前两项的和为第三项的数的数值用公式归纳起来为:f1=f2=1.f1=f1+f2.f2=f1+f2. 程序 ...

  2. POJ3641-Pseudoprime numbers(快速幂取模)

    题目大意 判断一个数是否是伪素数 题解 赤果果的快速幂取模.... 代码: #include<iostream> #include<cmath> using namespace ...

  3. DIV遮罩层传值

    今天费了很大的劲儿才搞定!下面贴出代码和总结: 1.首先是前台代码: <%@ Page Title="" Language="C#" MasterPage ...

  4. (android 源码下开发应用程序) 如何在 Android 各 level ( 包含 user space 與 kernel space ) 使用dump call stack的方法

    http://janbarry0914.blogspot.com/2014/07/androiddump-call-stack.html dump call stack [文章重點] 了解 Andro ...

  5. puppet_list

  6. The Dangers of JavaScript’s Automatic Semicolon Insertion

    Although JavaScript is very powerful, the language’s fundamentals do not have a very steep learning ...

  7. (qsf文件 、 tcl文件 和 csv(txt)文件的区别) FPGA管脚分配文件保存、导入导出方法

    FPGA管脚分配文件保存方法 使用别人的工程时,有时找不到他的管脚文件,但可以把他已经绑定好的管脚保存下来,输出到文件里. 方法一: 查看引脚绑定情况,quartus -> assignment ...

  8. Hyper-V网络虚拟化--VM之间拷贝速度慢

    Hyper-V网络虚拟化后,两台VM使用的是同一个VM网卡,相同IP地址池,但是互相拷贝文件速度很慢,只有2M左右,拷贝同时ping延迟在2000ms,解决方法: 主机型号:HP ProLiant D ...

  9. 杂谈:你选择coco 还是unity3d?

    当一个人喜欢的时候,那么这样的兴趣是非常难改变的.你是否会改变自己想法?眼下而言,如今adobe 对flash开发处于维护的状态.为什么?是由于前期错误政策流失非常多人才,这一点也非常难避免.当今年湖 ...

  10. 实战RPM包制作

    在开发中经常会用到一些rpm包,但是一直没有自己手动制作过.今天在制作的时候意外地还解决了自己以前一直困惑的问题,就是怎么制作rpm debuginfo包,类似CentOS官网那样的debuginfo ...