poj 3311 Hie with the Pie(状态压缩DP+最短路)
来源:互联网 发布:淘宝店和微商的区别 编辑:程序博客网 时间:2024/04/29 03:43
用弗洛伊德算法预处理数据,然后送货员的路线可以理解为从0出发经过所有点,在其中任何一点停止,然后从这点回到0。从最后的点回到起点所需要走的路程经过预处理之后是可以直接得到的,需要计算的是从起点经过所有的点所需要的最短路程。
#include<stdio.h>#include<string.h>#define N 11int dp[1<<N][N],dis[N][N],st[N];int Min(int x,int y){ if(x<y) return x; return y;}void Init(){ int i; for(i=1; i<=11; i++) st[i]=1<<(i-1); return ;}int main(){ int n; Init(); while(scanf("%d",&n),n) { int i,j,k; memset(dis,0,sizeof(dis)); for(i=0; i<=n; i++) { for(j=0; j<=n; j++) scanf("%d",&dis[i][j]); } for(k=0; k<=n; k++) { for(i=0; i<=n; i++) { for(j=0; j<=n; j++) dis[i][j]=Min(dis[i][j],dis[i][k]+dis[k][j]); } } int tt=1<<n; memset(dp,0x3f,sizeof(dp)); dp[0][0]=0; for(i=1; i<=n; i++) dp[st[i]][i]=dis[0][i]; for(i=0; i<tt; i++) { for(j=1; j<=n; j++) { if(!(i&st[j])) continue; for(k=1; k<=n; k++) { if(j!=k&&(i&st[k])) dp[i][j]=Min(dp[i][j],dp[i-st[j]][k]+dis[k][j]); } } } int ans; ans=dp[(1<<n)-1][1]+dis[1][0]; for(i=2; i<=n; i++) ans=Min(dp[(1<<n)-1][i]+dis[i][0],ans); printf("%d\n",ans); } return 0;}
- poj 3311 Hie with the Pie(状态压缩DP+最短路)
- POJ 3311 Hie with the Pie(状态压缩DP)
- POJ 3311 Hie with the Pie(状态压缩DP)
- POJ 3311 Hie with the Pie(状态压缩dp)
- poj 3311 Hie with the Pie(状态压缩dp)
- POJ 3311 Hie with the Pie (BFS+最短路+状态压缩)
- POJ 3311 Hie with the Pie(Floyd+状态压缩DP)
- POJ 3311 Hie with the Pie //状态压缩DP
- POJ 3311 Hie with the Pie -- TSP 状态压缩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(状态压缩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 floyd+状态压缩dp
- POJ 3311 Hie with the Pie(Floyd+状态压缩DP)
- UVa OJ 152 排序?
- C#操作EXCEL
- FindWindow寻找窗口列表中第一个符合指定条件的顶级窗口
- 在进入Mapper之前的输入分片处理过程详解
- GetClassName
- poj 3311 Hie with the Pie(状态压缩DP+最短路)
- Boyer-Moore算法学习
- LeetCode - Same Tree
- 两个List<Model>集合合并 并且去重方式
- 单链表与代码
- Class文件格式解析
- ZYNQ学习笔记(一) HelloWorld实现
- 对新手有用的JavaScript开发小建议
- HDU--2829--Lawrence--斜率优化做法