POJ 3311 Hie with the Pie (状压DP)
来源:互联网 发布:apache ant zip maven 编辑:程序博客网 时间:2024/05/17 00:55
状态压缩DP
dp[i][j]表示在i状态(用二进制表示城市有没有经过)时最后到达j城市的最小时间
转移方程dp[i][j]=min(dp[i][k]+d[k][j],dp[i][j])
d[k][j]是k城市到j城市的最短距离 要先用flody处理
#include<bits.stdc++.h>using namespace std;int d[20][20],dp[1<<11][20];int n,m;void flody(){for(int k=0;k<=n;k++)for(int i=0;i<=n;i++)for(int j=0;j<=n;j++){if(d[i][k]+d[k][j]<d[i][j])d[i][j]=d[i][k]+d[k][j];}}void DP(){int ans=INT_MAX;for(int i=0;i<(1<<n);i++)for(int j=1;j<=n;j++) { if(i==(1<<(j-1)))dp[i][j]=d[0][j];elseif(i&(1<<(j-1))){dp[i][j]=INT_MAX;for(int k=1;k<=n;k++)if(k!=j&&(i&(1<<(k-1))))dp[i][j]=min(dp[i^(1<<(j-1))][k]+d[k][j],dp[i][j]);} } for(int i=1;i<=n;i++) ans=min(ans,dp[(1<<n)-1][i]+d[i][0]); printf("%d\n",ans);}int main(){while(scanf("%d",&n)==1&&n){for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)scanf("%d",&d[i][j]); flody(); DP();}return 0;}
2 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】
- BAT 批处理脚本 教程
- 个就每年投入没看到他一人就看他家的大门,等同于
- 退出MFC应用程序的方法集
- HDU 1106 排序 字符串模拟
- Storm on YARN
- POJ 3311 Hie with the Pie (状压DP)
- android在如果绘制自定义的bitmap,然后返回给ImageView
- Android SharaedPreferences 记住用户名密码
- 字符串-07. 说反话-加强版 (20)
- Windows服务创建及安装
- Java native
- JAVA 环境设置
- 无情的雨无情的你
- Android SharaedPreferences 记住用户名密码