PKU 3311 Hie with the Pie 状态DP
Floyd + 状态DP
Watashi的板子
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int INF = (int) 1e8; int dp[<<][]; //dp[S][v] 表示还需访问的集合为S, 现在在v点
int d[][];
int n; void floyd() {
for (int k = ; k <= n; k++) {
for (int i = ; i <= n; i++)
for (int j = ; j <= n; j++)
d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
}
} void print() {
for (int i = ; i <= n; i++) {
for (int j = ; j <= n; j++)
printf("%d ", d[i][j]);
puts("");
}
} int main() {
#ifdef Phantom01
freopen("PKU3311.txt", "r", stdin);
#endif // Phantom01 while (scanf("%d", &n)!=EOF) {
if (==n) break;
for (int i = ; i <= n; i++)
for (int j = ; j <= n; j++)
scanf("%d", &d[i][j]);
// print();
floyd();
// print(); for (int i = ; i <= n; i++)
for (int S = ; S < (<<(n+)); S++)
dp[S][i] = INF; dp[(<<(n+))-][] = ;
for (int S = (<<(n+))-; S >= ; S--) {
for (int v = ; v <= n; v++) {
for (int u = ; u <= n; u++) {
if (!(S&(<<u))) {
if (dp[S][v] < ) {
dp[S][v] = dp[S|(<<u)][u] + d[v][u];
} else {
dp[S][v] = min(dp[S][v], dp[S|(<<u)][u] + d[v][u]);
}
}
}
}
}
printf("%d\n", dp[][]);
} return ;
}
PKU 3311 Hie with the Pie 状态DP的更多相关文章
- POJ 3311 Hie with the Pie(DP状态压缩+最短路径)
题目链接:http://poj.org/problem?id=3311 题目大意:一个送披萨的,每次送外卖不超过10个地方,给你这些地方之间的时间,求送完外卖回到店里的总时间最小. Sample In ...
- poj 3311 Hie with the Pie
floyd,旅游问题每个点都要到,可重复,最后回来,dp http://poj.org/problem?id=3311 Hie with the Pie Time Limit: 2000MS Me ...
- POJ 3311 Hie with the Pie(Floyd+状态压缩DP)
题是看了这位的博客之后理解的,只不过我是又加了点简单的注释. 链接:http://blog.csdn.net/chinaczy/article/details/5890768 我还加了一些注释代码,对 ...
- poj3311 Hie with the Pie (状态压缩dp,旅行商)
Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3160 Accepted: 1613 ...
- poj 3311 Hie with the Pie dp+状压
Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4671 Accepted: 2471 ...
- POJ 3311 Hie with the Pie 最短路+状压DP
Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11243 Accepted: 5963 ...
- POJ 3311 Hie with the Pie(状压DP + Floyd)
题目链接:http://poj.org/problem?id=3311 Description The Pizazz Pizzeria prides itself in delivering pizz ...
- poj 3311 Hie with the Pie (TSP问题)
Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4491 Accepted: 2376 ...
- poj 3311 Hie with the Pie(状态压缩dp)
Description The Pizazz Pizzeria prides itself or more (up to ) orders to be processed before he star ...
随机推荐
- 用latex写简历
最近终于逐渐掌握了用Latex写中文简历的问题.首先就是必须基于交大前辈bin yuan的模板进行学习. 如果有了一般论文撰写和Beamer做PPT的经验,不难发现resume的模板也是遵循一套程式的 ...
- 关于Spring的69个面试问答——终极列表 (转)
这篇文章总结了一些关于Spring框架的重要问题,这些问题都是你在面试或笔试过程中可能会被问到的.下次你再也不用担心你的面试了,Java Code Geeks这就帮你解答. 大多数你可能被问到的问题都 ...
- hdu 1257/1800 - 贪心,dp
1257题目链接 一个序列划分子序列,每个子序列都是非增序列,问最少分成几个子序列 1800题目链接 一堆数分组,每组内数据严格递减,问最少分几组 -------------------------- ...
- HDU 1171 Big Event in HDU【01背包】
题意:给出n个物品的价值和数目,将这一堆物品分给A,B,问怎样分使得两者的价值最接近,且A的要多于B 第一次做的时候,没有思路---@_@ 因为需要A,B两者最后的价值尽可能接近,那么就可以将背包的容 ...
- css实现步骤条
实现效果 html <ul class="steps"> <li class="active">申请完成</li> < ...
- org.apache.ibatis.binding.BindingException: Parameter ‘brOrderNo’ not found. Available parameters ar
最近使用 mybatis 写项目的时候遇到报错:org.apache.ibatis.binding.BindingException: Parameter 'brOrderNo' not found. ...
- fwupdate-efi 与 grub2-common 冲突
在CentOS-7Minimal系统中使用命令如下命令yum groupinstall -y "GNOME Desktop"安装 图形界面时提示:fwupdate-efi 与 gr ...
- 数组名作为函数参数以及sizeof用法
来源:https://blog.csdn.net/jay_zhouxl/article/details/51745518 int f(int *p,char *a) { printf("p[ ...
- 【BZOJ 1208】[HNOI2004]宠物收养所
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用set搞. (因为规定了不会有相同特点值的东西. 所以可以不用multiset. 那么每次用lower_bound找离它最近的配对 ...
- UILite-MFC/WTL/DirectUI界面库
之前写了UILite库介绍: http://blog.csdn.net/zhangzq86/article/details/9093945 如今UILite库能够使用git訪问了: https://g ...