[TSP+floyd]POJ3311 Hie with the Pie
题意: 给i到j花费的地图 1到n编号 一个人要从1遍历n个城市后回到1
求最小的花费(可以重复走)
分析
http://www.cnblogs.com/Empress/p/4039240.html
TSP
因为可以重复走 所以先floyd一下求最短路
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- #include <climits>
- #include <cctype>
- #include <cmath>
- #include <string>
- #include <sstream>
- #include <iostream>
- #include <algorithm>
- #include <iomanip>
- using namespace std;
- #include <queue>
- #include <stack>
- #include <vector>
- #include <deque>
- #include <set>
- #include <map>
- typedef long long LL;
- typedef long double LD;
- #define pi acos(-1.0)
- #define lson l, m, rt<<1
- #define rson m+1, r, rt<<1|1
- typedef pair<int, int> PI;
- typedef pair<int, PI> PP;
- #ifdef _WIN32
- #define LLD "%I64d"
- #else
- #define LLD "%lld"
- #endif
- //#pragma comment(linker, "/STACK:1024000000,1024000000")
- //LL quick(LL a, LL b){LL ans=1;while(b){if(b & 1)ans*=a;a=a*a;b>>=1;}return ans;}
- //inline int read(){char ch=' ';int ans=0;while(ch<'0' || ch>'9')ch=getchar();while(ch<='9' && ch>='0'){ans=ans*10+ch-'0';ch=getchar();}return ans;}
- //inline void print(LL x){printf(LLD, x);puts("");}
- //inline void read(double &x){char c = getchar();while(c < '0') c = getchar();x = c - '0'; c = getchar();while(c >= '0'){x = x * 10 + (c - '0'); c = getchar();}}
- int dp[<<][], mp[][];
- int n;
- void floyd()
- {
- for(int k=;k<n;k++)
- for(int i=;i<n;i++)
- for(int j=;j<n;j++)
- mp[i][j]=min(mp[i][j], mp[i][k]+mp[k][j]);
- }
- int main()
- {
- #ifndef ONLINE_JUDGE
- freopen("in.txt", "r", stdin);
- freopen("out.txt", "w", stdout);
- #endif
- while(~scanf("%d", &n) && n)
- {
- n++;
- for(int i=;i<n;i++)
- for(int j=;j<n;j++)
- scanf("%d", &mp[i][j]);
- floyd();
- memset(dp, , sizeof(dp));
- dp[(<<n)-][]=;
- for(int s=(<<n)-;s>=;s--)
- for(int v=;v<n;v++)
- for(int u=;u<n;u++)
- if(!(s>> u & ))
- dp[s][v]=min(dp[s][v], dp[s | <<u][u]+mp[v][u]);
- printf("%d\n", dp[][]);
- }
- return ;
- }
POJ 3311
[TSP+floyd]POJ3311 Hie with the Pie的更多相关文章
- POJ3311 Hie with the Pie 【状压dp/TSP问题】
题目链接:http://poj.org/problem?id=3311 Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total ...
- poj3311 Hie with the Pie (状态压缩dp,旅行商)
Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3160 Accepted: 1613 ...
- [poj3311]Hie with the Pie(Floyd+状态压缩DP)
题意:tsp问题,经过图中所有的点并回到原点的最短距离. 解题关键:floyd+状态压缩dp,注意floyd时k必须在最外层 转移方程:$dp[S][i] = \min (dp[S \wedge (1 ...
- POJ3311 Hie with the Pie(状压DP,Tsp)
本题是经典的Tsp问题的变形,Tsp问题就是要求从起点出发经过每个节点一次再回到起点的距离最小值,本题的区别就是可以经过一个节点不止一次,那么先预处理出任意两点之间的最短距离就行了,因为再多走只会浪费 ...
- 【鸽】poj3311 Hie with the Pie[状压DP+Floyd]
题解网上一搜一大坨的,不用复述了吧. 只是觉得网上dp方程没多大问题,但是状态的表示含义模糊.不同于正常哈密顿路径求解,状态表示应当改一下. 首先定义一次移动为从一个点经过若干个点到达另一个点,则$f ...
- POJ3311 Hie with the Pie
The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortu ...
- Hie with the Pie(poj3311)
题目链接:http://poj.org/problem?id=3311 学习博客:https://blog.csdn.net/u013480600/article/details/19692985 H ...
- poj 3311 Hie with the Pie (TSP问题)
Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4491 Accepted: 2376 ...
- Hie with the Pie
Hie with the Pie poj-3311 题目大意:n+1个点,伪旅行商问题. 注释:n<=10. 想法:咳咳,第一道状压dp,下面我来介绍一下状压dp. 所谓dp,就是动态性决策规划 ...
随机推荐
- 使用blktrace排查iowait cpu高的问题
本文转自这里,blktrace在这种情况下的使用方法值得借鉴学习. ------------------------------------------------------------------ ...
- Android richtext
在项目开发过程中经常会遇到很多需要显示不同样式的,不同风格的文本信息:对此可以使用多个TextView来分别设置自已想要的样式以满足需求,但是使用多个TextView的方式不太好:使用多个TextVi ...
- SQL Server(基本) 关键字的使用 一
一, 基础关键字 -- 使用介绍 1,select 的使用(select 结果集) SELECT 列名称 FROM 表名称 以及: (*)是选取所有列的快捷方式. SELECT * FROM 表名称 ...
- C# 求斐波那契数列的前10个数字 :1 1 2 3 5 8 13 21 34 55
//C# 求斐波那契数列的前10个数字 :1 1 2 3 5 8 13 21 34 55 using System; using System.Collections.Generic; using S ...
- iOS开发——极光推送
1.到极光官网 https://www.jpush.cn/ 下载极光推送SDK. 具体如何集成最好参考官网的文档,以及一些失败的原因.文档非常详细,我也是参考集成的. 2.到极光推送官网注册自己的应用 ...
- C#基础总复习01
马上就快毕业了,准备把这几个月所学到的知识梳理一下,这儿所写的都是一些C#中最基础的东西(大牛不要笑话我,这也是我记录的一些笔记等等),希望能帮到一些正在学习这方面的知识的人,如果有写的不对的地方,望 ...
- 【HeadFirst设计模式】12.复合模式
定义: 复合模式结合两个或以上的模式,组成一个解决方案,解决一再发生的一般性问题. 要点: MVC模式是复合模式,结合了观察者模式.策略模式和组合模式. 模型使用了观察者模式,以便观察者更新,同时保存 ...
- GCC编译器入门
GCC(GNU Compiler Collection,GNU编译器套件),是由 GNU 开发的编程语言编译器.它是以GPL许可证所发行的自由软件,也是 GNU计划的关键部分.GCC原本作为GNU操作 ...
- java oop
/** 多层嵌套内部类, 调用时要层层往下调用 格式: 外部类.内部类1.内部类2 对象名 = new 外部类().new 内部类1().new 内部类2(); 对象名.属性/方法名(); */ cl ...
- "严格模式" use strict 详解
一.概述 除了正常运行模式,ECMAscript 5添加了第二种运行模式:"严格模式"(strict mode).顾名思义,这种模式使得Javascript在更严格的条件下运行. ...