POJ 3311 Hie with the Pie (状压DP)
来源:互联网 发布:pmp证书 知乎 编辑:程序博客网 时间:2024/05/17 05:18
题目地址:POJ 3311
这题基本可以算是TSP问题,先用floyd预处理出来任意两个间对的最短路,注意是有向边。。。然后定义dp[i][j]表示在i状态下最后一个经过的城市为j的最短时间。然后状压即可。
代码如下:
#include <iostream>#include <string.h>#include <math.h>#include <queue>#include <algorithm>#include <stdlib.h>#include <map>#include <set>#include <stdio.h>using namespace std;#define LL __int64#define pi acos(-1.0)const int mod=100000000;const int INF=0x3f3f3f3f;const double eqs=1e-8;int dp[1<<12][20];int d[20][20];void floyd(int n){ int i, j, k; for(k=0; k<=n; k++) { for(i=0; i<=n; i++) { for(j=0; j<=n; j++){ d[i][j]=min(d[i][j],d[i][k]+d[k][j]); } } }}int main(){ int n, i, j, tot, last, k, min1; while(scanf("%d",&n)!=EOF&&n) { for(i=0; i<=n; i++) { for(j=0; j<=n; j++) { scanf("%d",&d[i][j]); } } floyd(n); tot=1<<n; memset(dp,INF,sizeof(dp)); for(i=1;i<tot;i++){ for(j=0;j<n;j++){ if(i&(1<<j)){ last=i-(1<<j); if(!last) { dp[i][j+1]=d[0][j+1]; continue ; } for(k=0;k<n;k++){ if(last&(1<<k)){ dp[i][j+1]=min(dp[i][j+1],dp[last][k+1]+d[k+1][j+1]); } } } } } min1=INF; for(i=1;i<=n;i++){ dp[tot-1][i]+=d[i][0]; min1=min(min1,dp[tot-1][i]); } printf("%d\n",min1); } return 0;}
1 0
- poj 3311 Hie with the Pie (DP)
- POJ 3311--Hie with the Pie(状压dp+TSP)
- poj 3311 Hie with the Pie(状压dp)
- poj 3311 Hie with the Pie(floyd + 状压dp)
- Hie with the Pie - POJ 3311 状压dp
- POJ 3311 Hie with the Pie (状压DP)
- POJ 3311 Hie with the Pie (状压DP)
- POJ 3311 Hie with the Pie floyd+状压DP
- 【DP】 POJ 3311 Hie with the Pie 状压 TSP问题
- poj 3311 Hie with the Pie dp+状压
- POJ 3311 Hie with the Pie(状压DP + Floyd)
- POJ 3311 Hie with the Pie (状压DP)
- POJ 3311-Hie with the Pie(floyd+TSP 状压DP)
- poj 3311 Hie with the Pie 状压dp
- POJ 3311 Hie with the Pie (状压DP)
- POJ 3311 Hie with the Pie(状压dp+floyd)
- poj 3311 Hie with the Pie(Floyd+状压dp)
- POJ 3311 Hie with the Pie - 状压dp【TSP】
- 卡尔曼滤波的原理说明
- 怎样打开Win7事件查看器
- Android手机数据恢复——终结篇
- 加载JAVA源码
- 使用 Codec Engine 的 API 函数(七)
- POJ 3311 Hie with the Pie (状压DP)
- 《开始学Backbone.js》之第三章Backbone Models与Collections(五)
- Android Studio-build错误:app:mergeDebugResources FAILED
- [C++]LeetCode: 85 Integer to Roman
- 界面缓冲动画效果进入程序和页面的切换效果
- 【汽配云】传统汽配行业如何搭上互联网时代的末班车?
- 转载:用随机森林模型替代常用的回归和分类模型 http://blog.sciencenet.cn/u/lixinhai来自科学网博客李欣海
- 进程间通信 - 动态链接库实现
- 编辑框(EditText)介绍与应用