poj 3311 Hie with the Pie floyd+枚举排列
来源:互联网 发布:杭州宇石网络怎么样 编辑:程序博客网 时间:2024/05/11 04:40
题意:
有0~n共n+1个点,任意两点所需时间已知,现在要从0起遍历完1~n之间的所有点再回到0点,求所需的最小时间。
思路:
先用floyd求出任意两点之间的最小时间,再枚举从0出发后的遍历顺序,取最小的时间。
代码:
//poj 3311//sepNINE#include <iostream> #include <algorithm>using namespace std;const int maxN=16;int g[maxN][maxN];int a[maxN];int main(){int n,i,j,k;while(scanf("%d",&n)==1&&n){for(i=0;i<=n;++i)for(j=0;j<=n;++j)scanf("%d",&g[i][j]);for(k=0;k<=n;++k)for(i=0;i<=n;++i)for(j=0;j<=n;++j)g[i][j]=min(g[i][j],g[i][k]+g[k][j]);int ans=INT_MAX;for(i=0;i<=n;++i)a[i]=i;do{int sum=0;for(i=0;i<=n;++i)sum+=g[a[i]][a[(i+1)%(n+1)]];ans=min(ans,sum);}while(next_permutation(a+1,a+n+1));printf("%d\n",ans);}return 0;}
0 0
- poj 3311 Hie with the Pie floyd+枚举排列
- poj 3311 Hie with the Pie ,floyd + 枚举排列
- POJ 3311 Hie with the Pie(Floyd+状态压缩DP)
- poj 3311 Hie with the Pie(floyd + 状压dp)
- POJ 3311 Hie with the Pie (Floyd+状态压缩)
- POJ 3311 Hie with the Pie floyd+状压DP
- POJ 3311 Hie with the Pie(状压DP + Floyd)
- POJ 3311 Hie with the Pie(Floyd+状态压缩DP)
- POJ 3311 Hie with the Pie(Floyd+状态压缩DP)
- POJ 3311-Hie with the Pie(floyd+TSP 状压DP)
- POJ 3311 Hie with the Pie(状压dp+floyd)
- poj 3311 Hie with the Pie(Floyd+状压dp)
- poj 3311 Hie with the Pie floyd+状态压缩dp
- POJ 3311 Hie with the Pie(Floyd+状态压缩DP)
- Poj 3311 Hie with the Pie【Floyd+状压dp】
- poj 3311 Hie with the Pie(状态压缩DP+floyd)
- [POJ 3311]Hie with the Pie(状压DP+Floyd)
- Poj 3311 Hie with the Pie 【TSP+floyd】
- Android Studio能取代Eclipse吗?
- 代码生成器原理
- ASP.NET MVC Filter 类切面 Session 存储 Cookie存储权限控制
- 学密码学一定得学程序
- 变量原始值问题
- poj 3311 Hie with the Pie floyd+枚举排列
- 单片机中的液晶显示器
- 【java】九九乘法表的输出
- 【网页设计】验证表单是否为空
- SQL增删改查
- Fragment中相关类的介绍
- 用JSTL和el完成9*9乘法表
- struts2下实现文件下载功能
- vi/vim 基本使用方法