poj 3311 Hie with the Pie(TSP 状态压缩)
来源:互联网 发布:linux 进程调度命令 编辑:程序博客网 时间:2024/06/05 18:33
Description
The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortunately, due to cutbacks, they can afford to hire only one driver to do the deliveries. He will wait for 1 or more (up to 10) orders to be processed before he starts any deliveries. Needless to say, he would like to take the shortest route in delivering these goodies and returning to the pizzeria, even if it means passing the same location(s) or the pizzeria more than once on the way. He has commissioned you to write a program to help him.
Input
Input will consist of multiple test cases. The first line will contain a single integer n indicating the number of orders to deliver, where 1 ≤ n ≤ 10. After this will be n + 1 lines each containing n + 1 integers indicating the times to travel between the pizzeria (numbered 0) and the n locations (numbers 1 to n). The jth value on the ith line indicates the time to go directly from location i to location j without visiting any other locations along the way. Note that there may be quicker ways to go from i to j via other locations, due to different speed limits, traffic lights, etc. Also, the time values may not be symmetric, i.e., the time to go directly from location i to j may not be the same as the time to go directly from location j to i. An input value of n = 0 will terminate input.
Output
For each test case, you should output a single number indicating the minimum time to deliver all of the pizzas and return to the pizzeria.
Sample Input
30 1 10 101 0 1 210 1 0 1010 2 10 00
Sample Output
8
Source
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<string>#include<algorithm>#include<cstdlib>#include<set>#include<queue>#include<stack>#include<vector>#include<map>#define N 100010#define Mod 10000007#define lson l,mid,idx<<1#define rson mid+1,r,idx<<1|1#define lc idx<<1#define rc idx<<1|1const double EPS = 1e-11;const double PI = acos ( -1.0 );const double E = 2.718281828;typedef long long ll;const int INF = 1000010;using namespace std;int n;int dp[ ( 1 << 11 ) + 1][12];int mp[13][13];void floyed(){ for ( int k = 0; k < n; k++ ) for ( int i = 0; i < n; i++ ) for ( int j = 0; j < n; j++ ) mp[i][j] = min ( mp[i][j], mp[i][k] + mp[k][j] );}int main(){ while ( ~scanf ( "%d", &n ) && n ) { n++; for ( int i = 0; i < n; i++ ) for ( int j = 0; j < n; j++ ) scanf ( "%d", &mp[i][j] ); floyed(); for ( int i = 0; i < ( 1 << n ); i++ ) for ( int j = 0; j < n; j++ ) dp[i][j] = INF; dp[0][0] = 0; for ( int i = 0; i < ( 1 << n ); i++ ) { for ( int j = 0; j < n; j++ ) { if ( dp[i][j] == INF ) continue; for ( int k = 0; k < n; k++ ) { if ( i & ( 1 << k ) ) continue; if ( j == k ) continue; dp[ ( 1 << k ) | i][k] = min ( dp[ ( 1 << k ) | i][k], dp[i][j] + mp[j][k] ); } } } int ans = INF; int p=(1<<n)-1; for ( int i = 0; i < n; i++ ) if ( dp[p][i] + mp[i][1] < ans ) ans = dp[p][i] + mp[i][0]; cout<<ans<<endl; } return 0;}
- POJ 3311 Hie with the Pie -- TSP 状态压缩dp
- Poj 3311 Hie with the Pie 状态压缩(TSP)
- poj 3311 Hie with the Pie(TSP 状态压缩)
- POJ 3311 Hie with the Pie (状态压缩DP ,tsp问题)
- POJ 3311 Hie with the Pie (状态压缩DP ,TSP问题)
- poj 3311 Hie with the Pie (TSP)
- POJ 3311 Hie with the Pie(Floyd+状态压缩DP)
- POJ 3311 Hie with the Pie //状态压缩DP
- POJ 3311 Hie with the Pie (状态压缩DP)
- 状态压缩DP-Hie With the Pie(POJ 3311)
- POJ 3311 Hie with the Pie(状态压缩DP)
- POJ 3311 Hie with the Pie (Floyd+状态压缩)
- poj 3311 Hie with the Pie(状态压缩DP)
- POJ 3311 Hie with the Pie(Floyd+状态压缩DP)
- POJ 3311 Hie with the Pie 状态压缩DP
- POJ 3311 Hie with the Pie(Floyd+状态压缩DP)
- POJ - 3311 Hie with the Pie (状态压缩)
- POJ 3311 Hie with the Pie(状态压缩DP)
- 在 ACM竞赛中,为什么美国的公认的计算机名校,如 MIT,斯坦福、加州伯克利、卡内基梅隆,表现不如中国和俄罗斯的高校?
- 雅虎网站页面性能优化的34条黄金守则
- <script>元素
- 深入浅出面板数据分析
- 把数据库数据导入出来成EXCEL(SpringMVC+Mybatis+mysql+easyUI)
- poj 3311 Hie with the Pie(TSP 状态压缩)
- VS2008使用boost的正则表达库regex的环境配置
- 从贝叶斯方法谈到贝叶斯网络
- Android Volley完全解析(二),使用Volley加载网络图片
- 关于sscanf()处理字符串的总结
- js 对象
- DRAM中的DLL/PLL是什么?
- javaweb-中文乱码问题解决方案
- 题目1034:寻找大富翁