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. Gram矩阵 迁移学习 one-shot 之类

    格拉姆矩阵是由内积空间中的向量两两内积而得.格拉姆矩阵在向量为随机的情况下也是协方差矩阵.每个数字都来自于一个特定滤波器在特定位置的卷积,因此每个数字代表一个特征的强度,而Gram计算的实际上是两两特 ...

  2. cuda windows运行时间限制

    GTX1080的卡,8G的显存,写cuda时申请了2G的显存就莫名其妙的抛异常,昨天找了一天也没找出bug,去stackoverflow上问了下才知道是windows的事,需要修改注册表.问题链接 - ...

  3. ActiveMQ学习笔记(13)----Destination高级特性(一)

    1. Wildcards 1. Wildcards用来支持名字分层体系,它不是JMS规范的一部分,是ActiveMQ的扩展. ActiveMQ支持一下三种wildcards: 1. ".&q ...

  4. [USACO10NOV]奶牛的图片Cow Photographs 树状数组 递推

    Code: #include<cstdio> #include<algorithm> #include<string> #include<cstring> ...

  5. vue非空校验

    效果图 实现代码 //页面html <div> <ul class="listinfo"> <li> <span class=" ...

  6. js验证输入框

    项目开发中,都会有对表单form中的input输入框进行一些限制验证 如: <!DOCTYPE html><html lang="en"> <head ...

  7. [ZJOI2015]幻想乡战略游戏(点分树)

    题意自己看... 思路 没想到今(昨)天刷着刷着点分治的水题,就刷出来了一个点分树... 然后就疯狂地找题解,代码,最后终于把它给弄懂了. 点分树——动态点分治,对于此题来说,我们设u为当前的补给站位 ...

  8. 【CS-4476-project 6】Deep Learning

    AlexNet / VGG-F network visualized by mNeuron. Project 6: Deep LearningIntroduction to Computer Visi ...

  9. P1017 进制转换 (负进制转换)

    和平常的转化差不多 加多一步 如果余数 < 0, 那么余数减去除数(此时除数是负),商数加1 #include<cstdio> #define _for(i, a, b) for(i ...

  10. PID三种参数的理解

    来源:http://blog.gkong.com/liaochangchu_117560.ashx PID是比例.积分.微分的简称,PID控制的难点不是编程,而是控制器的参数整定.参数整定的关键是正确 ...