Gym-100648B: Hie with the Pie(状态DP)
题意:外卖员开始在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)的更多相关文章
- PKU 3311 Hie with the Pie 状态DP
Floyd + 状态DP Watashi的板子 #include <cstdio> #include <cstring> #include <iostream> # ...
- 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状态压缩+最短路径)
题目链接:http://poj.org/problem?id=3311 题目大意:一个送披萨的,每次送外卖不超过10个地方,给你这些地方之间的时间,求送完外卖回到店里的总时间最小. Sample In ...
- POJ 3311 Hie with the Pie(Floyd+状态压缩DP)
题是看了这位的博客之后理解的,只不过我是又加了点简单的注释. 链接:http://blog.csdn.net/chinaczy/article/details/5890768 我还加了一些注释代码,对 ...
- poj 3311 Hie with the Pie dp+状压
Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4671 Accepted: 2471 ...
- POJ3311 Hie with the Pie 【状压dp/TSP问题】
题目链接:http://poj.org/problem?id=3311 Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total ...
- 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
floyd,旅游问题每个点都要到,可重复,最后回来,dp http://poj.org/problem?id=3311 Hie with the Pie Time Limit: 2000MS Me ...
随机推荐
- MAC——Homebrew介绍和使用
一.Homebrew是什么 Homebrew是一款Mac OS平台下的软件包管理工具,拥有安装.卸载.更新.查看.搜索等很多实用的功能.简单的一条指令,就可以实现包管理,而不用你关心各种依赖和文件路径 ...
- maven的依赖范围scope
compile(编译范围) compile是默认的范围:如果没有提供一个范围,那该依赖的范围就是编译范 围.编译范围依赖在所有的classpath中可用,同时它们也会被打包. provided(已提供 ...
- python定时任务APScheduler
APScheduler定时任务 APScheduler 支持三种调度任务:固定时间间隔,固定时间点(日期),Linux 下的 Crontab 命令.同时,它还支持异步执行.后台执行调度任务. 一.基本 ...
- git merge合并分支; already up to date 现象, merger算法
https://git-scm.com/book/zh/v2/Git-%E5%88%86%E6%94%AF-%E5%88%86%E6%94%AF%E7%9A%84%E6%96%B0%E5%BB%BA% ...
- VirtualBox 配置 CentOS7网卡信息
在实际配置虚拟机的过程中,网络配置时候一个很繁琐的过程,经常一个点没注意到,就访问不了了.在此,做一个简单的教程以供后续使用时可以参考! 方法一: 使用NAT网络 1. 选择网卡 安装centos7的 ...
- 对javascript中call()方法的理解
call ( thisObj [, arg1 [, arg2 [, [, argN] ] ] ]) call()方法:官方介绍是,调用一个对象的一个方法,以另一个对象替换当前对象. call()方法 ...
- SQL Server 数据库启动过程(用户数据库加载过程的疑难杂症)
前言 本篇主要是上一篇文章的补充篇,上一篇我们介绍了SQL Server服务启动过程所遇到的一些问题和解决方法,可点击查看,我们此篇主要介绍的是SQL Server启动过程中关于用户数据库加载的流程, ...
- day17——序列化、os、sys、hashlib、collections
day17 序列化 json 两组4个方法: 1.dumps(序列化) -- loads(反序列) dumps(list):将对象转换成字符串 loads(str):将字符串转换成对象 list--s ...
- Python之路【第十九篇】:前端CSS
CSS 一.CSS概述 CSS是Cascading Style Sheets的简称,中文称为层叠式样式表,用来控制网页数据的表现,可以使网页的表现与数据内容分离. 学CSS后我们需要掌握的技能: 1. ...
- liunx下Oracle安装
1. 引言 将近一个月没有更新博客了,最近忙着数据库数据迁移工作:自己在服务器上搭建了oracle数据库,一步步走下来遇见很多BUG:现在自己记录下,方便以后有用上的地方: 2. 准备工作 oracl ...