题意:外卖员开始在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. (转)Intellij IDEA 2017 debug断点调试技巧与总结详解篇

    背景:详细介绍idea的debug调试过程 Intellij IDEA 2017 debug断点调试技巧与总结详解篇

  2. netty内存数据缓冲区使用策略

    主要是通过AbstractByteBufAllocator类实现的ByteBuffer的申请. 代码如下: @Override public ByteBuf ioBuffer(int initialC ...

  3. Access to XMLHttpRequest at 'http://127.0.0.1:8000/XXXXX' from origin 'http://localhost

    Django 报错,跨域请求出现问题. 在settings.py中添加 #设置可跨域范围 CORS_ALLOW_CREDENTIALS = True CORS_ORIGIN_ALLOW_ALL = T ...

  4. Java生产消费者模型——代码解析

    我们将生产者.消费者.库存.和调用线程的主函数分别写进四个类中,通过抢夺非线程安全的数据集合来直观的表达在进行生产消费者模型的过程中可能出现的问题与解决办法. 我们假设有一个生产者,两个消费者来共同抢 ...

  5. C++11 新特性之智能指针(shared_ptr, unique_ptr, weak_ptr)

    这是C++11新特性介绍的第五部分,涉及到智能指针的相关内容(shared_ptr, unique_ptr, weak_ptr). shared_ptr shared_ptr 基本用法 shared_ ...

  6. 函数式接口java.util.function

    什么是函数式接口 为什么要用函数式接口 java.util.function和其他的函数式接口 lamdba表达式 方法引用 流 Stream 1 什么是函数式接口 用@FunctionInterfa ...

  7. 在windows服务中使用定时器

    在windows服务中,利用winform中直接拖动timer控件的方式使用定时器是不可以的,启动服务后会发现定时器并没有执行.那么在windows服务中如何使用定时器呢?  不使用直接拖动控件的方式 ...

  8. 用cProfile做性能分析【转】

    原文地址: https://www.cnblogs.com/kaituorensheng/p/4453953.html

  9. A Deep Dive Into Draggable and DragTarget in Flutter

    https://medium.com/flutter-community/a-deep-dive-into-draggable-and-dragtarget-in-flutter-487919f6f1 ...

  10. Stack布局中定位的方式

    //……省略无关代码…… child: new Column( children: <Widget>[ new SizedBox(height: 20.0), new Stack( ali ...