题目链接: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. ERROR hdfs.DFSClient: Failed to close file解决方法

    14/04/11 17:59:44 ERROR hdfs.DFSClient: Failed to close file /wlan_out/_temporary/_attempt_local_000 ...

  2. C++中字符串的结尾标志\0

    \0是C++中字符串的结尾标志,存储在字符串的结尾,它虽然不计入串长,但要占一个字节的内存空间.在百度百科中查看\0词条,会有这样一句话:c/c++中规定字符串的结尾标志为'\0'.有人可能认为,在C ...

  3. .NET Compact Framework Data Provider for SQL Server CE

    .NET Compact Framework Data Provider for SQL Server Mobile Standard Data Source=MyData.sdf;Persist S ...

  4. Redis学习资料汇总(荐)

    Redis学习手册系列: http://www.cnblogs.com/stephen-liu74/category/354125.html Redis详解:sorted sets数据类型及操作-IT ...

  5. hdoj 2553 N皇后问题【回溯+打表】

    N皇后问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  6. 三角形div的原理

    三角形div原理 首先我们写一个正常的方形div样式,但是我们把它的宽度和高度都设置为零,并且边框线设置的粗一点: { width:0px: height:0px; Border:20px solid ...

  7. 2假动作,数据缓冲,CCEaseExponential,CCEaseElastic,CCEaseBounce,CCCallFunc,funcNCallBack,funcNDCallBack,funcO

     1 缓冲动作 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdG90b3R1enVvcXVhbg==/font/5a6L5L2T/fontsize/4 ...

  8. 二叉树可视化--Graphviz

    大家平时写C程序有没有种把内存里的数据结构全给画出来的冲动呢?数据量小的话,画起来还蛮简单,用viso,我前面的文章都用viso画的.之前写红黑树代码的时候,用的是命令行把整个树打印出来,不过只是一些 ...

  9. linux和windows中设置环境变量经常使用命令

    Linux和Windows下查看环境变量方法 一.查看全部环境变量的名称和值: Linux下:export Windows下:set 二.依据名称查该环境变量的值: Linux下:echo $环境变量 ...

  10. 判断URL是否存在

    判断URL是否存在   判断网址是否存在,可以使用下面方面处理.如果HttpStatusCode为OK,说明网址存在.