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

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. Codeforces 556D - Case of Fugitive

    556D - Case of Fugitive 思路:将桥长度放进二叉搜索树中(multiset),相邻两岛距离按上限排序,然后二分查找桥长度匹配并删除. 代码: #include<bits/s ...

  2. Python mysql-表中数据的大量插入

    2017-09-06 23:28:26 import pymysql db = pymysql.connect("localhost","root"," ...

  3. docker添加国内仓库安装iredmail

    centos 7: 1.yum install docker or yum update docker sudo tee /etc/docker/daemon.json <<-'EOF'{ ...

  4. 『PyTorch』第七弹_nn.Module扩展层

    有下面代码可以看出torch层函数(nn.Module)用法,使用超参数实例化层函数类(常位于网络class的__init__中),而网络class实际上就是一个高级的递归的nn.Module的cla ...

  5. 手动安装Silverlight 4 Tools for Visual Studio 2010

    手动安装吧,将Silverlight 4 Tools for Visual Studio 2010.exe改成rar文件,解压缩,按照下面的步骤安装: 1.silverlight_developer. ...

  6. OC self注意事项

    #import <Foundation/Foundation.h> @interface Person : NSObject - (void)test; + (void)test; - ( ...

  7. spoj8406

    题解: 二分+树状数组 记录以下i在当前拍第几 代码: #include<bits/stdc++.h> using namespace std; ; int a[N],f1[N],f2[N ...

  8. pywin32 的安装

    这个东西不是在包管理器安装一下就可以的. https://github.com/mhammond/pywin32/releases 请到git下载exe安装文件.

  9. Pycharm(三)常用设置

    File - Settings (ctrl+alt+s) python模板 Editor - File and Code Templates - Python Script 可以使用部分变量. # ! ...

  10. 2.4 C++成员选择符

    参考:http://www.weixueyuan.net/view/6336.html 总结: 访问可以通过成员选择符“.”或指针操作符“->”来完成. 通过上一节的学习我们看到:通过对象可以访 ...