poj3311 Hie with the Pie
来源:互联网 发布:js注册界面源代码 编辑:程序博客网 时间:2024/04/27 22:36
题目链接:Hie with the Pie
TSP水题。。题意很简单,一个人送pizza,给出这个人在这些城市间送pizza的时间,从0出发,遍历城市1~n,并回到0,求最短时间是多少。
思路:因为一个城市可以多次跑,所以先floyd,dp[i][j]中i表示状态,j表示城市,初始化就是i==1<<(j-1)的时候了,dp[i][j]由所有满足k != j && (1<<(k-1) & i)的k转移过来,最后取加上从i到0的距离最小值就行了。
#include<stdio.h>#include<iostream>#include<string.h>#include<math.h>#include<stdlib.h>#include<map>#include<set>#include<sstream>#include<vector>#include<string>#include<queue>#include<algorithm>#define mod 100000000#define INF 1000000000#define maxn (1<<10)#define CEN 45000#define ll __int64using namespace std;int n,mp[15][15],dp[maxn][15],maxm;int main(){ int i,j,k,ans; while(scanf("%d",&n) && n) { maxm = 1<<n; ans=INF; n++; for(i=0;i<n;i++) for(j=0;j<n;j++) scanf("%d",&mp[i][j]); for(k=0;k<n;k++) for(i=0;i<n;i++) for(j=0;j<n;j++) mp[i][j] = min(mp[i][j] , mp[i][k] + mp[k][j]); for(i=0;i<maxm;i++) for(j=0;j<12;j++) dp[i][j] = INF; for(i=0;i<maxm;i++) for(j=1;j<n;j++) { if((1<<(j-1) == i)) dp[i][j] = mp[0][j]; else if((1<<(j-1) & i)) { for(k=1;k<n;k++) if(k != j && (1<<(k-1) & i)) dp[i][j] = min ( dp[i][j] , dp[(i^(1<<(j-1)))][k] + mp[k][j] ); } } for(i=1;i<n;i++) ans = min( ans , dp[maxm-1][i] + mp[i][0] ); printf("%d\n",ans); } return 0;}
0 0
- poj3311 Hie with the Pie
- POJ3311 Hie with the Pie
- poj3311 Hie with the Pie
- poj3311 Hie with the Pie
- Hie with the Pie poj3311
- POJ3311 Hie with the Pie
- poj3311(Hie with the Pie)状压dp
- POJ3311 Hie with the Pie解题报告
- POJ3311 Hie with the Pie 状压DP
- poj3311 Hie with the Pie,状态压缩
- POJ3311——Hie with the Pie
- [POJ3311] Hie with the Pie && 状压DP
- [ 状压DP][POJ3311] Hie with the Pie
- POJ3311 Hie with the Pie(状态压缩dp)
- POJ3311:Hie with the Pie(floyd+状态压缩DP)
- poj3311 Hie with the Pie(最短路+状态dp)
- poj3311--Hie with the Pie(状压dp)
- 【POJ3311】Hie with the Pie(状态压缩DP)
- How to use pylab to plot figure()?
- Android拷贝工程不覆盖原工程的配置方法
- CodeBlocks集成Objective-C开发
- 传感器学习案例 之 公交防盗
- no installed service named "apache2"
- poj3311 Hie with the Pie
- java基础第三天
- 警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property ...
- s3c2440裸板程序四个led轮流灭
- 不兼容结构的协调——适配器模式(三)
- 获取一个想要的指定文件的集合,获取文件夹下(包含子目录的所有.java的文件对象,并存储到集合中)
- jquery 对 Json 的各种遍历
- HDU 1044 Collect More Jewels(BFS+DFS)
- RPC原理