poj 3311 Hie with the Pie ,floyd + 枚举排列
来源:互联网 发布:全球主权财富基金知乎 编辑:程序博客网 时间:2024/05/18 19:47
题意:给出一个图,求从0开始走,经过所有节点再回到0的最小时间。
先用floyd处理一遍,找出两个点之间的最短路径,然后枚举排列找最小值。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int mp[11][11];int v[20];int main() { int n, i, j, k; while(~scanf("%d", &n) && n) { for(i = 0; i <= n; i++) { for(j = 0; j <= n; j++) scanf("%d", &mp[i][j]); } for(i = 0; i <= n; i++) { for(j = 0; j <= n; j++) { for(k =0 ; k <= n; k++) { if(mp[j][k] > mp[j][i] + mp[i][k]) mp[j][k] = mp[j][i] + mp[i][k]; } } } for(i = 0; i <= n; i++) { v[i] = i; } int ans = 0x3f3f3f3f; do{ int t = 0; for(i = 1; i <= n; i++) { t += mp[v[i - 1]][v[i]]; } t += mp[v[n]][0]; if(t < ans) ans = t; }while(next_permutation(v + 1, v + 1 + n)); 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】
- 八大内部排序算法总结
- adb logcat 命令行用法 .
- 编写Python脚本来获取Google搜索结果的示例
- Xamarin.Android release-Apk 瘦身策略
- 4687. 【NOIP2016提高A组8.12】奇袭
- poj 3311 Hie with the Pie ,floyd + 枚举排列
- Android Init进程源码分析
- Java String 类型编码转换
- 【线段树】今天我种了一棵线段树
- Leetcode 233. Number of Digit One (Medium) (cpp)
- Redis集群方案
- Pro Android学习笔记(一四二):触摸屏(1):MotionEvents
- MySQL约束
- Ubuntu下hadoop1.21伪分布式搭建