poj 3311 Hie with the Pie
来源:互联网 发布:图坦卡蒙的诅咒 知乎 编辑:程序博客网 时间:2024/05/22 09:01
题目
枚举经过的点,,,
dp[i][j]表示到j点状态为i时的最小花费
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define Max 100000000int n;int dis[12][12];int dp[1<<12+5][12];int main(){ while(scanf("%d",&n)&&n) { for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) { scanf("%d",&dis[i][j]); } for(int k=0;k<=n;k++) for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]); int sta= 1<<(n+1); for(int i=0;i<sta;i++) for(int j=0;j<=n;j++) dp[i][j]=Max; for(int i=0;i<=n;i++) dp[1<<i][i]=dis[0][i]; for(int i=0;i<sta;i++) { for(int j=0;j<=n;j++) { if(i&(1<<j)) { for(int k=0;k<=n;k++) { if(i&(1<<k)) { dp[i][j]=min(dp[i][j],dp[i&(~(1<<j))][k]+dis[k][j]); } } } } } printf("%d\n",dp[sta-1][0]); }}
- poj 3311 Hie with the Pie
- POJ 3311 Hie with the Pie
- poj 3311 Hie with the Pie
- poj 3311 Hie with the Pie
- poj 3311 Hie with the Pie (TSP)
- POJ 3311 — Hie with the Pie
- POJ 3311 Hie with the Pie
- poj 3311 Hie with the Pie (DP)
- POJ 3311 Hie with the Pie
- POJ 3311 Hie with the Pie
- POJ - 3311 Hie with the Pie
- POJ 3311 - Hie with the Pie
- POJ 3311 Hie with the Pie
- POJ 3311 Hie with the Pie
- Hie with the Pie POJ
- Hie with the Pie POJ
- Hie with the Pie POJ
- POJ 3311 Hie with the Pie(Floyd+状态压缩DP)
- JQuery:渐隐渐显图片轮换幻灯片
- 生成 android web service 客户端代码
- c# 处理大批量数据 时遇到 类型为“System.OutOfMemoryException”的异常
- 做什么职业,也别做程序员
- linux下解压命令大全
- poj 3311 Hie with the Pie
- 能获取ContentPresenter节点下的节点
- 转载 基本的图像采集流程
- Android内存优化
- sql性能优化
- MVC4中使用Jquery.Multifile.js和Jquery.form.js一次上传多个文件
- 硬链接不能跨分区的错误
- 软RAID磁盘阵列学习笔记
- CListCtrl控件主要事件及LVN_ITEMCHANGED消息和鼠标双击列表项事件的处理