POJ 3311 状压+Floyd
来源:互联网 发布:mmd 动作数据 r-18 编辑:程序博客网 时间:2024/06/15 19:29
题意
N个客户,外卖员需要将外卖送给N个客户。0代表外卖店,1-N代表客户地址。矩阵i,j代表从i到j所需时间。求送完所有外卖最少所需时间。
题解
先使用Flyod算法求出任意两点间最短路(数据量很小,Flyod很轻松)。然后dp[i][j]代表状态i,当前状态所处位置为j。dp[i][j]=min(dp[i^1<<(j-1)][k]+dis[k][j],dp[i][j]),求出动态规划方程后剩下的就是老套路了。
代码
#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>#define INF 1e9using namespace std;int n;int dis[15][15];int dp[1050][15];int main(){ while(~scanf("%d",&n)){ memset(dp,0,sizeof(dp)); if(n==0) break; 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 mx=1<<n; for(int i=0;i<mx;i++){ for(int j=1;j<=n;j++){ if(i&1<<(j-1)){ if(i==1<<(j-1)) dp[i][j]=dis[0][j]; else{ dp[i][j]=INF; for(int k=1;k<=n;k++){ if((i&1<<(k-1))&&(k!=j)){ dp[i][j]=min(dp[i^1<<(j-1)][k]+dis[k][j],dp[i][j]); } } } } } } int ans=dp[mx-1][1]+dis[1][0]; for(int i=2;i<=n;i++){ ans=min(ans,dp[mx-1][i]+dis[i][0]); } printf("%d\n",ans); } return 0;}
0 0
- POJ 3311 状压+Floyd
- poj 3311 floyd + 状态
- poj 3311(floyd+状态压缩)
- poj 3311 Hie with the Pie(floyd + 状压dp)
- POJ 3311 Hie with the Pie floyd+状压DP
- POJ 3311 Hie with the Pie(状压DP + Floyd)
- POJ 3311-Hie with the Pie(floyd+TSP 状压DP)
- POJ 3311 Hie with the Pie(状压dp+floyd)
- poj 3311 Hie with the Pie(Floyd+状压dp)
- Poj 3311 Hie with the Pie【Floyd+状压dp】
- [POJ 3311]Hie with the Pie(状压DP+Floyd)
- POJ 3311 Hie with the Pie Floyd+状压dp
- POJ 3311 Hie with the Pie(Floyd + 状压dp)
- POJ 3311 Hie with the Pie (Floyd+状压DP)
- POJ 3311状压dp+floyd--TSP问题(货郎担问题||旅行商问题)
- POJ 3311 Hie with the Pie (Floyd + 状压dp 简单TSP问题)
- 旅行商问题 TSP问题 状压dp入门 + floyd poj 3311 hdu 5418
- 状压DP (Floyd+状态压缩 )——Hie with the Pie( POJ 3311 )
- CodeForces 276 D.Little Girl and Maximum XOR(位运算)
- yes 这是~4月份学习计划
- 实例浅析IO阻塞、非阻塞epoll的水平触发和边缘触发
- 学习Linux命令(1)
- windows下安装redis 以及phpredis的扩展 (windows redis php&php7)
- POJ 3311 状压+Floyd
- Python运维之获取系统CPU信息
- 鸟哥的linux私房菜学习笔记2
- Linux Kernel 学习笔记1:module的基本结构和编译
- 如何解决常见的缓存穿透、并发和失效问题?
- BelgaLogos数据集分析
- 哈希算法---sort 前M大的数
- 线程同步的API
- 链表的有序集合