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)的邻接 ...
随机推荐
- $P2299 Mzc和体委的争夺战$
\(problem\) #ifdef Dubug #endif #include <bits/stdc++.h> using namespace std; typedef long lon ...
- JavaScript--控制类名(className 属性)
className 属性设置或返回元素的class 属性. 语法: object.className = classname 作用: 1.获取元素的class 属性 2. 为网页内的某个元素指定一个c ...
- 解决gradle project refresh failed: protocol family unavailable问题的几种方法
Android Studio从版本1.5更新到2.1之后,打开Android Studio一直提示: gradle project refresh failed: protocol family un ...
- [转]Linux下paste命令详解
转自:http://blog.csdn.net/andy572633/article/details/7214126 paste单词意思是粘贴.该命令主要用来将多个文件的内容合并,与cut命令完成的功 ...
- 【转】Linux 之 数据流重定向
转自:http://www.linuxidc.com/Linux/2012-09/69764.htm linux在你登入时,便将默认的标准输入.标准输出.标准错误输出安排成你的终端.I/O重定向就是你 ...
- SQL Sever语言 事务
事务:保障流程的完整执行保证程序某些程序在运行时同时成功同时失败,保证程序的安全性 begin tran --在流程开始的位置加 --此处写SQL语句 if @@error>0 --ERRORS ...
- 【RTTI】java Class类详解
RTTI (Run-Time Type Information)运行时类信息 Java的Class类是java反射机制的基础,通过Class类我们可以获得关于一个类的相关信息,下面我们来了解一下有关j ...
- [ NOIP 2008 ] TG
\(\\\) \(\#A\) \(Word\) 给出一个长为\(N\)的小写字母串,判断出现所有字母中最多出现次数减最少出现次数得到的答案是否是质数. \(N\in [1,100]\) 直接按题意开桶 ...
- fcc html5 css 练习3
行内样式看起来是这样的 <h1 style="color: green"> .pink-text { color: pink !important; } ...
- html 报告页面 v1.2 批量数据生成表格
html 报告页面 v1.2 批量数据生成表格 上代码: <!DOCTYPE html> <html lang="en"> <head> < ...