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问题的最小解 ...
随机推荐
- JSON和JS对象之间的互转【转】
1. jQuery插件支持的转换方式 $.parseJSON( jsonstr ); //jQuery.parseJSON(jsonstr),可以将json字符串转换成json对象 2. 浏览器支持的 ...
- Hibernate入门第二课 Hibernate Tools for Eclipse Plugins安装
Hibernate入门第二课 Hibernate Tools for Eclipse Plugins安装 你们可以直接去,http://blog.csdn.net/wei_chong_chong/ar ...
- 『cs231n』卷积神经网络工程实践技巧_上
概述 数据增强 思路:在训练的时候引入干扰,在测试的时候避免干扰. 翻转图片增强数据. 随机裁切图片后调整大小用于训练,测试时先图像金字塔制作不同尺寸,然后对每个尺寸在固定位置裁切固定大小进入训练,最 ...
- IDEA搭建ssm框架测试衍生出的问题The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\Develop\jdk7\jdk1.7.0_79\bin;
最近玩起IDEA这开发工具,搭建ssm框架测试时,部署项目出现如下问题: 信息: The APR based Apache Tomcat Native library which allows opt ...
- python-day4笔记
1.文件后缀名对python运行没关系 2.Python解释器执行python程序的过程:python3 C:\test.py 1)启动python解释器(内存中) 2)将C:\test.py内容从硬 ...
- 对象不能从 DBNull 转换为其他类型
SQL语句:select sum (datediff(second,Begin_Time,End_Time)) as 总时长 from 数据表这是我开始的程序:int 总时长=0;总时长 =Conve ...
- java并发编程:线程安全管理类--原子操作类--AtomicReferenceFieldUpdater<T,V>
1.类 AtomicReferenceFieldUpdater<T,V> public abstract class AtomicReferenceFieldUpdater<T,V& ...
- bzoj2463
题解: 当n为奇数,输出Bob 否则输出Alice 代码: #include<bits/stdc++.h> using namespace std; int n; int main() { ...
- Oracle11g 查询长时间运行的SQL
一.大量的查询 某些时候,因为SQL的问题,导致数据库的session大量积压,服务器的磁盘读增大,CPU使用率剧增.一般这种SQL,都是一些全表扫描.多表关联.报表或者排序类的SQL.这中情况很有可 ...
- Pycharm(五)安装库和虚拟环境
随便进入一个项目 进入设置 Ctrl + alt + S Project ********* - Project Interpreter ******是你的项目名字 Project I ...