下面是别人的解题报告链接:

http://blog.csdn.net/accry/article/details/6607703

下面是我的代码,我觉得链接中的代码有一点小问题,也许是我想错了吧。

 #include <cstdio>
#define min(a,b) (a) < (b) ? (a) : (b);
#define INF 100000000
int dist[][];
int dp[][];
void init(int n)
{
for(int i=; i<=n; ++i)
for(int j=; j<=n; ++j)
scanf("%d",&dist[i][j]);
for(int k =; k <=n; ++k)
for(int i=; i<=n; ++i)
for(int j=; j<=n; ++j)
dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
}
int main()
{
// freopen("in.cpp","r",stdin);
int n;
while(scanf("%d",&n), n)
{
init(n);
int sn = <<(n+);//状态数
for(int i=; i<sn; ++i)
for(int j=; j<=n; ++j)
dp[i][j] = INF;
for(int i=; i<=n; ++i)
dp[(<<i)][i] = dist[][i];
for(int k=; k<sn; ++k)
{
for(int i=; i<=n; ++i)
{
if(! (k & (<<i) )) continue;
for(int j=; j<=n; ++j)
{
if( j != i && k & ( << j) )
dp[k][i] = min(dp[k][i] , dp[k^(<<i)][j]+dist[j][i] );
}
}
}
printf("%d\n",dp[sn-][]);
}
return ;
}

POJ 3311 Hie with the Pie 先用floyd预处理,再状态压缩的更多相关文章

  1. poj 3311 Hie with the Pie

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

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

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

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

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

  4. POJ 3311 Hie with the Pie:TSP(旅行商)【节点可多次经过】

    题目链接:http://poj.org/problem?id=3311 题意: 你在0号点(pizza店),要往1到n号节点送pizza. 每个节点可以重复经过. 给你一个(n+1)*(n+1)的邻接 ...

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

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

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

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

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

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

  8. POJ 3311 Hie with the Pie(DP状态压缩+最短路径)

    题目链接:http://poj.org/problem?id=3311 题目大意:一个送披萨的,每次送外卖不超过10个地方,给你这些地方之间的时间,求送完外卖回到店里的总时间最小. Sample In ...

  9. [POJ 3311]Hie with the Pie——谈论TSP难题DP解决方法

    主题连接:  id=3311">http://poj.org/problem?id=3311 题目大意:有n+1个点,给出点0~n的每两个点之间的距离,求这个图上TSP问题的最小解 ...

随机推荐

  1. spring boot: freemarket模板引擎

    spring boot: freemarket模板引擎 freemarket模板引擎,可以和thymeleaf模板引擎共存 pom.xml引入 <!-- Freemarket --> &l ...

  2. 12月14日 bs-grid , destroy_all()

    bootstrap Grid : The Bs grid system has four classes: xs (phones), sm (tablets), md (desktops), and ...

  3. Sasha and Interesting Fact from Graph Theory CodeForces - 1109D (图论,计数,Caylay定理)

    大意: 求a->b最短路长度为m的n节点树的个数, 边权全部不超过m 枚举$a$与$b$之间的边数, 再由拓展$Caylay$定理分配其余结点 拓展$Caylay$定理 $n$个有标号节点生成k ...

  4. 删除php数组中的元素

    删除一个元素,且保持原有索引不变 使用 unset 函数,示例如下: <?php $array = array(0 => "a", 1 => "b&qu ...

  5. linux 查找

    linux下的查找命令有很多,常用的有which.whereis.locate.find.平时在网上搜索一些教程的时候,经常会有让使用这四条命令中的一条去查找一些东西,但是经常这次说用which,下次 ...

  6. 『PyTorch』第五弹_深入理解autograd_中:Variable梯度探究

    查看非叶节点梯度的两种方法 在反向传播过程中非叶子节点的导数计算完之后即被清空.若想查看这些变量的梯度,有两种方法: 使用autograd.grad函数 使用hook autograd.grad和ho ...

  7. Android studio jni

    首先我们要明确几个概念,jni,ndk,共享库(.so). jni是java native interface的缩写,java 本地接口.它提供了若干的API实现了Java和其他语言的通信(主要是C/ ...

  8. Mvc 学习笔记(一)

    1. MVC 表示 模型-视图-控制器.MVC是一种用于开发应用程序的模式,具备良好的架构,可测试和易于维护.基于MVC应用程序中包含: Models:表示应用程序的数据,并使用验证逻辑强制执行业务规 ...

  9. httpclient妙用一 httpclient作为客户端调用soap webservice(转)

    前面有一篇使用HttpClient调用带参数的post接口方法,这里找到一篇使用HttpClient调用Soap协议接口的方式. 原文地址:httpclient妙用一 httpclient作为客户端调 ...

  10. Hibernate---运行原理

    Hibernate---运行原理