POJ 3311
设dp状态为dp[i][j]为当前访问过的结点状态为i且当前停留点为j时的最短路径。用二进制存存储访问过的状态,访问过为1,否则为0。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
const int inf=(1<<30);
int map[12][12];
int dp[1<<11][12],n; struct Status{
int i,j,v;
Status(){}
Status(int ii,int jj,int vv){i=ii,j=jj,v=vv;}
}que[(1<<11)*12];
int head,tail; void slove(){
while(head<tail){
Status tmp=que[head++];
if(tmp.v>dp[tmp.i][tmp.j]) continue;
for(int j=0;j<=n;j++){
int st=(1<<j);
int tst=tmp.i|st;
if(dp[tst][j]>tmp.v+map[tmp.j][j]){
dp[tst][j]=tmp.v+map[tmp.j][j];
que[tail++]=Status(tst,j,dp[tst][j]);
}
}
}
printf("%d\n",dp[(1<<n+1)-1][0]);
} int main(){
while(scanf("%d",&n),n){
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++)
scanf("%d",&map[i][j]);
}
for(int i=0;i<(1<<(n+1));i++){
for(int j=0;j<=n;j++)
dp[i][j]=inf;
}
dp[1][0]=0;
head=tail=0;
que[tail++]=Status(1,0,0);
slove();
}
return 0;
}
POJ 3311的更多相关文章
- poj 3311(状态压缩DP)
poj 3311(状态压缩DP) 题意:一个人送披萨从原点出发,每次不超过10个地方,每个地方可以重复走,给出这些地方之间的时间,求送完披萨回到原点的最小时间. 解析:类似TSP问题,但是每个点可以 ...
- Hie with the Pie POJ - 3311
Hie with the Pie POJ - 3311 The Pizazz Pizzeria prides itself in delivering pizzas to its customers ...
- Hie with the Pie (POJ 3311) 旅行商问题
昨天想练习一下状态压缩,百度搜索看到有博客讨论POJ 3311,一看就是简单的旅行商问题,于是快速上手写了状态压缩,死活样例都没过... 画图模拟一遍原来多个城市可以重复走,然后就放弃思考了... 刚 ...
- poj 3311(floyd+状态压缩)
题目链接:http://poj.org/problem?id=3311 思路:Floyd + 状态压缩DP 题意是有N个城市(1~N)和一个PIZZA店(0),要求一条回路,从0出发,又回到0,而且 ...
- 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状态压缩+最短路径)
题目链接:http://poj.org/problem?id=3311 题目大意:一个送披萨的,每次送外卖不超过10个地方,给你这些地方之间的时间,求送完外卖回到店里的总时间最小. Sample In ...
- 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——谈论TSP难题DP解决方法
主题连接: id=3311">http://poj.org/problem?id=3311 题目大意:有n+1个点,给出点0~n的每两个点之间的距离,求这个图上TSP问题的最小解 ...
- 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)的邻接 ...
随机推荐
- WP8开发常用解决方案收集
我其实不怎么做wp的东西.但是偶尔还是会用到, 但是wp8开发的资料确实难找.特开此贴,记录一些常见的解决方案 1.水平滑动动画(比如app首次使用说明就可以用这个做) http://www.cnbl ...
- NS2学习笔记(二)
Tcl语言 变量和变量赋值 set a "Hello World!" #将字符串赋值给变量a puts "NS2 say $a" #输出字符串的内容,其中$a表 ...
- jmeter中对于各类时间格式的设置
最普通的设置为使用 函数助手中的__time, 设置好需要使用的类型,并设置接收参数即可 YMD = yyyyMMdd HMS = HHmmss YMDHMS = yyyyMMdd-HHmmss 第二 ...
- BZOJ 1845 Simpson积分
思路: Simpson积分直接上 限制一下递归深度+精度就好了 (难以理解为什么这么多人写扫描线) //By SiriusRen #include <bits/stdc++.h> usi ...
- action="post" 、 servletconfig 、 servletcontext 、getPrintWiter() 、context-param、 init-param(第一个完整的servlet)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...
- 淘宝ip地址库接口会导致TTFB时间变长,网站打开速度变慢
前一段时间闲来无事发现别人的网站上有显示当前用户城市的功能,就自己也整了一个 这是淘宝ip地址库调用方法 然后问题就出现了,网站打开速度慢的要死 用F12发现是TTFB太慢,然后百度了,发现了问题的原 ...
- [Windows Server 2008] 安装Apache+PHP+MySQL
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:Win2008 ...
- dotnetnuke 添加用户属性 Profile
if (DotNetNuke.Entities.Profile.ProfileController.GetPropertyDefinitionByName(this.PortalId, "Q ...
- 【译】x86程序员手册14-5.1段转换
5.1 Segment Translation 段转换 Figure 5-2 shows in more detail how the processor converts a logical add ...
- MVC5+EasyUI+EF6+Linq通用权限系统出炉(1)
1.先晒一下结构吧,