POJ 3311 Hie with the Pie 先用floyd预处理,再状态压缩
下面是别人的解题报告链接:
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预处理,再状态压缩的更多相关文章
- poj 3311 Hie with the Pie
floyd,旅游问题每个点都要到,可重复,最后回来,dp http://poj.org/problem?id=3311 Hie with the Pie Time Limit: 2000MS Me ...
- POJ 3311 Hie with the Pie(状压DP + Floyd)
题目链接:http://poj.org/problem?id=3311 Description The Pizazz Pizzeria prides itself in delivering pizz ...
- POJ 3311 Hie with the Pie floyd+状压DP
链接:http://poj.org/problem?id=3311 题意:有N个地点和一个出发点(N<=10),给出全部地点两两之间的距离,问从出发点出发,走遍全部地点再回到出发点的最短距离是多 ...
- POJ 3311 Hie with the Pie:TSP(旅行商)【节点可多次经过】
题目链接:http://poj.org/problem?id=3311 题意: 你在0号点(pizza店),要往1到n号节点送pizza. 每个节点可以重复经过. 给你一个(n+1)*(n+1)的邻接 ...
- poj 3311 Hie with the Pie dp+状压
Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4671 Accepted: 2471 ...
- poj 3311 Hie with the Pie (TSP问题)
Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4491 Accepted: 2376 ...
- POJ 3311 Hie with the Pie 最短路+状压DP
Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11243 Accepted: 5963 ...
- POJ 3311 Hie with the Pie(DP状态压缩+最短路径)
题目链接:http://poj.org/problem?id=3311 题目大意:一个送披萨的,每次送外卖不超过10个地方,给你这些地方之间的时间,求送完外卖回到店里的总时间最小. Sample In ...
- [POJ 3311]Hie with the Pie——谈论TSP难题DP解决方法
主题连接: id=3311">http://poj.org/problem?id=3311 题目大意:有n+1个点,给出点0~n的每两个点之间的距离,求这个图上TSP问题的最小解 ...
随机推荐
- 30分钟带你了解Springboot与Mybatis整合最佳实践
前言:Springboot怎么使用想必也无需我多言,Mybitas作为实用性极强的ORM框架也深受广大开发人员喜爱,有关如何整合它们的文章在网络上随处可见.但是今天我会从实战的角度出发,谈谈我对二者结 ...
- dp练习(6)——搬运礼物
3409 搬运礼物 CodeVS原创 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 青铜 Bronze 题解 题目描述 Description 小浣熊松松特别喜欢交 ...
- Scrum介绍——续
四. Scrum过程 Scrum的过程如图4-1所示 图4-1 Scrum过程 4.1 建立Product Backlog Product Backlog是Product Owner把客户的商业需求按 ...
- $digest already in progress 解决办法——续
什么时候手动调用$apply()方法? 如果AngularJS总是将我们的代码wrap到一个function中并传入$apply(),以此来开始一轮$digest循环,那么什么时候才需要我们手动地调用 ...
- vue-cli的安装及使用
一. node 和npm 1.在安装vue-cli前,要确认自己的电脑是否安装了node和npm 2.查询版本如下(vue脚手架支持node@4.xx以上) node -v 查询node版 ...
- 无名管道跟dup,dup的使用
参考资料: http://www.tldp.org/LDP/lpg/node11.html http://blog.csdn.net/yeyuangen/article/details/6852682 ...
- Java多线程的同步控制记录
Java多线程的同步控制记录 一.重入锁 重入锁完全可以代替 synchronized 关键字.在JDK 1.5 早期版本,重入锁的性能优于 synchronized.JDK 1.6 开始,对于 sy ...
- html <frame>标签使用
标签定义 frameset 中的一个特定的窗口(框架) frameset中的每个框架都可以设置不同的属性,比如border,scrolling,noresize等 frame的常用属性 width: ...
- React教程-组件
在React中创建一个组件非常简单(React组件有2种,一个非状态组件,一个有状态组件) 首先我们来看看ES6里面如何写构造函数 class App{ constructor(){ } event( ...
- bzoj1648
题解: 简单灌水 然后统计一下 代码: #include<bits/stdc++.h> using namespace std; ; int ne[N],num,fi[N],n,k,m,x ...