题意:外卖员开始在0号节点,有N个人点了外卖,(N<=10),现在告诉两两间距离,问怎么配送,使得每个人的外卖都送外,然后回到0号点的总时间最短,注意,同一个点可以多次经过。

思路:TSP问题(货郎担问题),可以通过状态DP解决小数据问题。 先floyd求一下两两最近距离,然后DP;

dp[i][j]表示经过状态为i,当前在j号节点是最小耗时。 ans=min(dp[S][i]+dis[i][0]);

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
int dp[maxn][],dis[][],N,cnt,ans,S;
int Laxt[maxn],Next[maxn],To[maxn],Len[maxn];
void floyd()
{
rep(k,,N)
rep(i,,N)
rep(j,,N) if(dis[i][j]>dis[i][k]+dis[k][j])
dis[i][j]=dis[i][k]+dis[k][j];
}
void solve()
{
S=(<<(N+))-;
dp[][]=;
rep(i,,S){
rep(k,,N)
rep(j,,N){
dp[i|(<<j)][j]=min(dp[i][k]+dis[k][j],dp[i|(<<j)][j]);
}
}
}
int main()
{
while(~scanf("%d",&N)&&N){
memset(dp,,sizeof(dp));
rep(i,,N) Laxt[i]=; cnt=;
rep(i,,N)
rep(j,,N)
scanf("%d",&dis[i][j]);
floyd();
solve();
ans=dp[S][]+dis[][];
rep(i,,N) ans=min(ans,dp[S][i]+dis[i][]);
printf("%d\n",ans);
}
return ;
}

Gym-100648B: Hie with the Pie(状态DP)的更多相关文章

  1. PKU 3311 Hie with the Pie 状态DP

    Floyd + 状态DP Watashi的板子 #include <cstdio> #include <cstring> #include <iostream> # ...

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

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

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

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

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

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

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

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

  6. POJ3311 Hie with the Pie 【状压dp/TSP问题】

    题目链接:http://poj.org/problem?id=3311 Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total ...

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

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

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

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

  9. poj 3311 Hie with the Pie

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

随机推荐

  1. Python学习之路:关于列表(List)复制的那点事

    要谈列表的复制,我们就要谈到Python的赋值规则 首先我们创建列表a: a = [1,2,3] 通常我们复制一个元素的方法是这样的: b = a #复制元素的一般方法 print(a) print( ...

  2. c#学习笔记1-简单算法

    using System; namespace Demo { class Studycs { public static void Main(String[] args) { // String re ...

  3. Linux目录结构(目录结构详解是重点)

    1.Linux目录与Windows目录对比 1.Windows目录结构 2.Linux目录结构 深刻理解Linux 树状文件目录是非常重要的,只有记住他们,你才能在命令行中任意切换,想去哪里去哪里 2 ...

  4. JAVA十六进制数据接收与传输

    一.十六进制转换工具类 主要包含十六进制字符串转ASCII,ASCII转十六进制字符串以及十六进制字符串转Byte数组等方法: /** * Created by wly on 2018/4/17. * ...

  5. Drool7s kmodule的作用--系列02课

    本文是介绍drool7s kmodule. 一.为什么komdule.xml文件一定要放在resources下的META-INF文件夹中 --->直接看源码吧,请看下图,应该都知道为什么要放在固 ...

  6. ASP.NET Nlog上手练习小例子

    添加NuGet程序包-             Nlog             Nlog.Web.AspNetCore 两个包. public void Configure(IApplication ...

  7. DNS原理及劫持问题

    对于互联网,人们总是高谈阔论,却很少有人愿意去了解电脑.手机.电视这些设备到底是如何被“连接”起来的.本文通过“我”,一个普通的网络请求的视角,给大家介绍下“我”的工作流程是如何的. 人们动动手指,点 ...

  8. 【Java基础】- Java学习路线图

    Java的学习路线图,整理以备自己学习和温习. 1.Java基础 具体内容: 1. 编程基础(开发环境配置.基础语法.基本数据类型.流程控制.常用工具类) 2. 面向对象(继承.封装.多态.抽象类.接 ...

  9. CSS3扇形进度效果

    .coutdown-animate {     position: absolute;     top: 0;     left: 0;     right: 0;     bottom: 0;    ...

  10. kubeadm部署高可用K8S集群(v1.14.2)

    1. 简介 测试环境Kubernetes 1.14.2版本高可用搭建文档,搭建方式为kubeadm 2. 服务器版本和架构信息 系统版本:CentOS Linux release 7.6.1810 ( ...