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 ...
随机推荐
- IEEE Access的模板的问题
这个模板果然问题还是有一些,比如caption换行得自己改class文件.首先感谢一下CSDN的一位网友的经验https://blog.csdn.net/baidu_21381705/article/ ...
- n阶方阵,数字从1~n^2,顺时针增大
运行结果如下图: 解题思路:可以将这个问题分解成x个外围正方形所围成的图形,外围的正方形又可以分为4个步骤,向右依次增大.向下依次增大.向左依次增大.向上依次增大.基本思路就是如此,最关键的就是什么时 ...
- (转)JVM内存管理-----堆内存
来源:http://blog.csdn.net/yu422560654/article/details/7952613 Heap堆内存理解 一个JVM实例只有一个堆内存,堆内存的大小是可以调节的.类加 ...
- js 将数组中的每一项安装奇偶重新组合成一个数组对象
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- LCT笔记
先存个代码 #include<iostream> #include<cstring> #include<cstdio> #include<cmath> ...
- [HAOI2015]树上染色(树形dp)
[HAOI2015]树上染色 题目描述 有一棵点数为 N 的树,树边有边权.给你一个在 0~ N 之内的正整数 K ,你要在这棵树中选择 K个点,将其染成黑色,并将其他 的N-K个点染成白色 . 将所 ...
- CSDN博客给我带来的一些诱惑和选择机会
武汉九天鸟-p2p网贷系统开发-互联网应用软件开发 公司官网:http://jiutianniao.com 社交问答:http://ask.jiutianniao.com 最近1年多,尤其是今年5月 ...
- 网页里如何使用js禁用F12事件
接上一篇,突然想起来,类似于网页里如何使用js禁用鼠标右击事件,还有禁用F12事件也可以禁用一下,总所周知,对于Web开发人员来说,常常要进行界面的调试.使用F12调试工具能够很方便地进行调试,查看h ...
- 网页里如何使用js屏蔽鼠标右击事件
图片.png 在后台管理系统里面,遇到了这样的一个问题,右击ztree菜单,弹出修改界面,但是,现在确实这样的,右击默认弹出功能提示的框框,看上去似乎很影响自己想要的功能,只能禁用了,那么,网页里如何 ...
- Max Points on a Line(直线上最多的点数)
给定一个二维平面,平面上有 n 个点,求最多有多少个点在同一条直线上. 示例 1: 输入: [[1,1],[2,2],[3,3]] 输出: 3 解释: ^ | | o | o | ...