状压dp Hie with the Pie
来源:互联网 发布:淘宝领的红包在哪里 编辑:程序博客网 时间:2024/06/16 00:06
题目地址
题目大意:有n个顾客,给出各个点之间的直接距离,从披萨店给这n个顾客送餐,在回到披萨店,求最短路径(可以反复走)披萨店在0点,
思路:这个题其实也不难,但是一开始我自己较真了,想着不就是遍历一张地图嘛,忽略了可以回头再走的情况,样例走不出来。。自己又在思考,发现错误后不会改,,,搜了题解后,看到题解的处理方法后才是真的恍然大悟!!!自己竟然想不到!!!惭愧!!做状压dp做到这,这个题真的不难,就是这一步for循环更新给点之间的最短距离思维有点nice!
代码:
#include<iostream>#include<cstring>#include<stdio.h>#include<cmath>#include<algorithm>#include<vector>#define inf 0x3f3f3f3f3fusing namespace std;int N,a[15][15],dp[1<<11][15];int main(){ int i,j,k,l,ans,z; while(~scanf("%d",&N)) { ans=0; if(N==0) break; memset(dp,inf,sizeof(dp)); l=(1<<(N+1))-1; //cout<<dp[l][0]<<endl; for(i=0;i<N+1;i++) for(j=0;j<N+1;j++) scanf("%d",&a[i][j]); for(i=1;i<=N;i++) dp[1<<i][i]=a[0][i]; for(i=0;i<=N;i++) for(j=0;j<=N;j++) for(k=0;k<=N;k++) if(a[i][j]>a[i][k]+a[k][j]) a[i][j]=a[i][k]+a[k][j]; for(i=1;i<l;i++) for(j=1;j<=N;j++) { if(i&1<<j) { z=i-(1<<j); for(k=1;k<=N;k++) { if((i&1<<k)&&k!=j) { dp[i][j]=min(dp[i][j],dp[z][k]+a[k][j]); //cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j]<<" "<<dp[z][k]<<endl; } } } } dp[l][0]=0x3f3f3f3f; for(int i=1;i<=N;i++) { dp[l][0]=min(dp[l][0],dp[l-1][i]+a[i][0]); } printf("%d\n",dp[l][0]); }}
阅读全文
0 0
- poj3311(Hie with the Pie)状压dp
- POJ3311 Hie with the Pie 状压DP
- [POJ3311] Hie with the Pie && 状压DP
- [ 状压DP][POJ3311] Hie with the Pie
- 状压DP D - Hie with the Pie
- 状压dp Hie with the Pie
- 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)
- poj3311--Hie with the Pie(状压dp)
- C++ 扩展和嵌入 Python
- 判断网络的状态
- 容器vector&list
- (二)java框架篇笔记库(15)
- 网络回调
- 状压dp Hie with the Pie
- Eclipse项目出现红色叹号的解决办法
- MVP+RxJava+Retrofit使用GET解析拼参数
- 吴恩达(Andrew Ng)深度学习工程师笔记
- (安卓)属性动画 (平移,旋转,透明)
- 命令注入突破长度限制 | 从CTF题目讲起
- 解锁css3新姿势之transform3D各属性及transform兼容之矩阵写法
- 【PAT】1003. 我要通过!(20) C++语言 浙江大学PAT上机题
- mysql -5.7 的安装