poj 3311 Hie with the Pie (TSP)
来源:互联网 发布:指针怎么指向二维数组 编辑:程序博客网 时间:2024/05/16 15:23
dp[state][j] 表示在state的状态下 当前位置在j的最小路程
状态转移:dp[i][j]=min(dp[i][j],dp[i^(1<<j)][k]+dis[k][j]);
#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>#define inf 0x3f3f3f3fusing namespace std;int map[12][12];int dis[12][12];int dp[1<<12][12];int main(){ int n; while(scanf("%d",&n)!=EOF && 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<=n;i++) for(int j=0;j<=n;j++) { dis[i][j]=map[i][j]; dis[i][i]=0; } for(int k=0;k<=n;k++) for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) dis[i][j]=dis[i][j]>dis[i][k]+dis[k][j]?dis[i][k]+dis[k][j]:dis[i][j]; memset(dp,0,sizeof dp); for(int i=1;i<(1<<(n+1));i++) { i|=1; for(int j=1;j<=n;j++) { if((1<<j)&i) { if(i==((1<<j)|1)) { dp[i][j]=dis[0][j]; } else { dp[i][j]=inf; for(int k=1;k<=n;k++) { if(((1<<k)&i) && k!=j) { dp[i][j]=min(dp[i][j],dp[i^(1<<j)][k]+dis[k][j]); } } } } } } int ans=inf; for(int i=1;i<=n;i++) ans=min(ans,dp[(1<<(n+1))-1][i]+dis[i][0]); printf("%d\n",ans); } return 0;}
0 0
- poj 3311 Hie with the Pie (TSP)
- POJ 3311--Hie with the Pie(状压dp+TSP)
- POJ 3311 Hie with the Pie -- TSP 状态压缩dp
- poj 3311 Hie with the Pie (TSP问题)
- 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(floyd+TSP 状压DP)
- POJ 3311 Hie with the Pie - 状压dp【TSP】
- POJ 3311 Hie with the Pie(TSP问题DP解)
- POJ 3311 Hie with the Pie TSP问题 -
- Poj 3311 Hie with the Pie 【TSP+floyd】
- POJ 3311 Hie with the Pie(经典TSP问题)
- POJ 3311 Hie with the Pie(经典TSP问题)
- poj 3311 Hie with the Pie(TSP ,状压dp)
- POJ 3311 Hie with the Pie (TSP问题 状压DP解法)
- [POJ 3311]Hie with the Pie——再谈TSP问题的DP解法
- POJ 3311 Hie with the Pie (Floyd + 状压dp 简单TSP问题)
- 10种排序算法总结
- Power Strings
- 2013:云计算的夏天
- 自动装箱和拆箱引出的享元模式
- Eclipse更改字体大小
- poj 3311 Hie with the Pie (TSP)
- 如何以特定的时间间隔为图片添加动画效果?
- Linux oracle 10g EM、ISQLPLUS 按钮乱码解决
- Android 程序的快捷方式
- PreparedStatement查询注意点(CHAR类型结果找不到)
- [python start]如何让内网其他人访问本机程序
- POJ 3301 Texas Trip
- Python+Visual Studio
- Valid Parentheses