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的更多相关文章

  1. POJ 3311 Hie with the Pie(DP状态压缩+最短路径)

    题目链接:http://poj.org/problem?id=3311 题目大意:一个送披萨的,每次送外卖不超过10个地方,给你这些地方之间的时间,求送完外卖回到店里的总时间最小. Sample In ...

  2. poj 3311 Hie with the Pie

    floyd,旅游问题每个点都要到,可重复,最后回来,dp http://poj.org/problem?id=3311 Hie with the Pie Time Limit: 2000MS   Me ...

  3. POJ 3311 Hie with the Pie(Floyd+状态压缩DP)

    题是看了这位的博客之后理解的,只不过我是又加了点简单的注释. 链接:http://blog.csdn.net/chinaczy/article/details/5890768 我还加了一些注释代码,对 ...

  4. poj3311 Hie with the Pie (状态压缩dp,旅行商)

    Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3160   Accepted: 1613 ...

  5. poj 3311 Hie with the Pie dp+状压

    Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4671   Accepted: 2471 ...

  6. POJ 3311 Hie with the Pie 最短路+状压DP

    Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11243   Accepted: 5963 ...

  7. POJ 3311 Hie with the Pie(状压DP + Floyd)

    题目链接:http://poj.org/problem?id=3311 Description The Pizazz Pizzeria prides itself in delivering pizz ...

  8. poj 3311 Hie with the Pie (TSP问题)

    Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4491   Accepted: 2376 ...

  9. poj 3311 Hie with the Pie(状态压缩dp)

    Description The Pizazz Pizzeria prides itself or more (up to ) orders to be processed before he star ...

随机推荐

  1. eclipse01

    http://blog.csdn.net/luman1991/article/category/6354903

  2. HDU 2122 Ice_cream’s world III【最小生成树】

    解题思路:基础的最小生成树反思:不明白为什么i从1开始取,就一直WA,难道是因为村庄的编号是从0开始的吗 Ice_cream’s world III Time Limit: 3000/1000 MS ...

  3. Mojo Core Embedder API

    This document is a subset of the Mojo documentation. Contents Overview Basic Initialization IPC Init ...

  4. P2421 [NOI2002]荒岛野人 扩展欧几里得 枚举

    Code: #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ...

  5. css兼容性问题总结

    DIV+CSS设计IE6.IE7.FF 兼容性 DIV+CSS网页布局这是一种趋势,我也开始顺应这股趋势了,不过在使用DIV+CSS网站设计的时候,应该注意css样式兼容不同浏览器问题,特别是对完全使 ...

  6. 6、DRN-----深度强化学习在新闻推荐上的应用

    1.摘要: 提出了一种新的深度强化学习框架的新闻推荐.由于新闻特征和用户喜好的动态特性,在线个性化新闻推荐是一个极具挑战性的问题. 虽然已经提出了一些在线推荐模型来解决新闻推荐的动态特性,但是这些方法 ...

  7. python 中进制转换及format(),int()函数用法

    python中数值型变量好像只能是十进制形式表示,其他类型变量只能以字符串形式存在,可以通过format函数将int类型变量转换成其他进制字符串,如下所示: v_code=15 # 2进制 x=for ...

  8. BNUOJ 34990 Justice String

    Justice String Time Limit: 2000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java cla ...

  9. C++模板遇到iterator时候遇到的问题和解决方法

    今天开发的时候,发现用模板的时候,再加上iterator,会报错,如下: std::map<T, S>::iterator find_iter = mp.find(key); 编译会报错: ...

  10. LightOJ - 1038 Race to 1 Again 递推+期望

    题目大意:给出一个数,要求你按一定的规则将这个数变成1 规则例如以下,如果该数为D,要求你在[1,D]之间选出D的因子.用D除上这个因子,然后继续按该规则运算.直到该数变成1 问变成1的期望步数是多少 ...