hdu 4114 Disney's FastPass 状压dp
Disney's FastPass
Time Limit: 20 Sec Memory Limit: 256 MB
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=4114
Description
Disney's FastPass is a virtual queuing system created by the Walt
Disney Company. First introduced in 1999 (thugh the idea of a ride
reservation system was first introduced in world fairs), Fast-Pass
allows guests to avoid long lines at the attractions on which the system
is installed, freeing them to enjoy other attractions during their
wait. The service is available at no additional charge to all park
guests.
--- wikipedia
Disneyland
is a large theme park with plenties of entertainment facilities, also
with a large number of tourists. Normally, you need to wait for a long
time before geting the chance to enjoy any of the attractions. The
FastPass is a system allowing you to pick up FastPass-tickets in some
specific position, and use them at the corresponding facility to avoid
long lines. With the help of the FastPass System, one can arrange
his/her trip more efficiently.
You are given the map of the whole
park, and there are some attractions that you are interested in. How to
visit all the interested attractions within the shortest time?
Input
Each test case contains several lines.
The
first line contains three integers N,M,K(1 <= N <= 50; 0 <= M
<= N(N - 1)/2; 0 <= K <= 8), indicating the number of
locations(starting with 1, and 1 is the only gate of the park where the
trip must be started and ended), the number of roads and the number of
interested attractions.
The following M lines each contains three
integers A,B,D(1 <= A,B <= N; 0 <= D <= 10^4) which means it
takes D minutes to travel between location A and location B.
The following K lines each contains several integers Pi, Ti, FTi,Ni, Fi,1, Fi,2 ... Fi,Ni-1, FiNi ,(1 <= Pi,Ni, Fi,j <=N, 0 <= FTi <= Ti <= 10^4), which means the ith interested araction is placed at location Pi and there are Ni locations Fi,1; Fi,2 ... Fi,Ni
where you can get the FastPass for the ith attraction. If you come to
the ith attraction with its FastPass, you need to wait for only FTi
minutes, otherwise you need to wait for Ti minutes.
You can assume that all the locations are connected and there is at most one road between any two locations.
Note that there might be several attrractions at one location.
Output
For each test case in the input, print one line: "Case #X: Y", where X is the test case number (starting with 1) and Y is the minimum time of the trip.
Sample Input
2
4 5 2
1 2 8
2 3 4
3 4 19
4 1 6
2 4 7
2 25 18 1 3
4 12 6 1 3
4 6 2
1 2 5
1 4 4
3 1 1
3 2 1
3 4 1
2 4 10
2 8 3 1 4
4 8 3 1 2
Sample Output
HINT
题意
游戏园里有N个区域,有M条边连接这N个区域,有K个要访问的景点。对于每个景点告诉你这个景点所在的区域,要访问这个景点需要等待一定时间,如果没有 FastPass,等待时间有Ti,否则等待时间为FTi,接下来的Ni,表示有Ni个区域可以得到这个景点的FastPass,问从区域1出发,再回到 区域1所需要的最少时间。
题解:
状态压缩dp
http://blog.csdn.net/shiqi_614/article/details/11265439
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 100
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** int dis[maxn][maxn];
int dp[maxn][<<][<<];
int pas[<<];
int ans;
int t[maxn],ft[maxn],pos[maxn];
int n,m,k;
void init()
{
ans=inf;
memset(dp,0x3f,sizeof(dp));
memset(dis,0x3f,sizeof(dis));
memset(pas,,sizeof(pas));
}
void flyod()
{
for(int k=;k<=n;k++)
{
for(int i=;i<=n;i++)
{
if(i!=k)
for(int j=;j<=n;j++)
{
if(j!=i&&j!=k)
dis[i][j]=min(dis[i][k]+dis[k][j],dis[i][j]);
}
}
}
}
void solve()
{
dp[][][]=;
for(int s1=;s1<(<<k);s1++)
{
for(int s2=;s2<(<<k);s2++)
{
for(int i=;i<=n;i++)
{
int now=dp[i][s1][s2]; if(now==inf) continue; if(s2==((<<k)-)) ans=min(ans,now+dis[i][]); for(int j=;j<k;j++) if((s2&(<<j))==)
{
int &nxt=dp[pos[j]][ s1|pas[ pos[j] ] ][s2^(<<j)]; int add=dis[i][pos[j]];
if(s1&(<<j)) add+=ft[j];
else add+=t[j]; nxt=min(nxt,now+add);
}
for(int j=;j<=n;j++)
{
int &nxt=dp[j][s1|pas[j]][s2];
int add=dis[i][j];
nxt=min(nxt,now+add);
}
}
}
}
//return ans;
}
int main()
{
//freopen("test.txt","r",stdin);
int tt=read();
for(int cas=;cas<=tt;cas++)
{
init(); scanf("%d%d%d",&n,&m,&k);
for(int i=;i<n;i++) dis[i][i]=;
for(int i=;i<m;i++)
{
int a,b,c; scanf("%d%d%d",&a,&b,&c);
dis[a][b]=dis[b][a]=c;
} flyod(); for(int i=;i<k;i++)
{
scanf("%d%d%d",&pos[i],&t[i],&ft[i]);
int num; scanf("%d",&num);
for(int j=;j<num;j++)
{
int tmp; scanf("%d",&tmp);
pas[tmp]|=(<<i);
}
}
solve();
printf("Case #%d: %d\n",cas,ans);
}
}
hdu 4114 Disney's FastPass 状压dp的更多相关文章
- HDU 6149 Valley Numer II 状压DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6149 题意:中文题目 解法:状压DP,dp[i][j]代表前i个低点,当前高点状态为j的方案数,然后枚 ...
- HDU 5434 Peace small elephant 状压dp+矩阵快速幂
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5434 Peace small elephant Accepts: 38 Submissions: ...
- HDU 1074 Doing Homework(状压DP)
第一次写博客ORZ…… http://acm.split.hdu.edu.cn/showproblem.php?pid=1074 http://acm.hdu.edu.cn/showproblem.p ...
- HDU 4906 Our happy ending (状压DP)
HDU 4906 Our happy ending pid=4906" style="">题目链接 题意:给定n个数字,每一个数字能够是0-l,要选当中一些数字.然 ...
- HDU 1074 Doing Homework (状压dp)
题意:给你N(<=15)个作业,每个作业有最晚提交时间与需要做的时间,每次只能做一个作业,每个作业超出最晚提交时间一天扣一分 求出扣的最小分数,并输出做作业的顺序.如果有多个最小分数一样的话,则 ...
- HDU 4568 Hunter 最短路+状压DP
题意:给一个n*m的格子,格子中有一些数,如果是正整数则为到此格子的花费,如果为-1表示此格子不可到,现在给k个宝藏的地点(k<=13),求一个人从边界外一点进入整个棋盘,然后拿走所有能拿走的宝 ...
- HDU 1074 Doing Homework【状压DP】
Doing Homework Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he ...
- HDU 4899 Hero meet devil (状压DP, DP预处理)
题意:给你一个基因序列s(只有A,T,C,G四个字符,假设长度为n),问长度为m的基因序列s1中与给定的基因序列LCS是0,1......n的有多少个? 思路:最直接的方法是暴力枚举长度为m的串,然后 ...
- HDU 5657 CA Loves Math 状压DP + 枚举
题意: 给出\(A(2 \leq A \leq 11), n(0 \leq n \leq 10^9), k(1 \leq k \leq 10^9)\). 求区间\([1, A^n]\)中各个数字互不相 ...
随机推荐
- 数据库管理软件 Navicat Premium12 破解步骤
数据库管理软件 Navicat Premium12B https://pan.baidu.com/s/1QnAQwW-q0SQ1JglpFGxKOA 密码 : mwqc 里面的软件和补丁是 ...
- i8042 键盘控制器-------详细介绍
[转]http://shanzy.bokee.com/834368.html ps/2 键盘硬件概述 对于驱动来说,和键盘相关的最重要的硬件是两个芯片.一个是 intel 8042 芯片,位于主板上, ...
- 函数参数 f_arg, *args, **kwargs
当需要给函数传参时,可以通过运用不同的形参来传递,达到参数不同的使用目的. 简单来说:f_arg就是传递的第一个参数,类似于C++中的普通参数: *args 传递的是一个参数的list: **kwar ...
- 基于AQS实现的Java并发工具类
本文主要介绍一下基于AQS实现的Java并发工具类的作用,然后简单谈一下该工具类的实现原理.其实都是AQS的相关知识,只不过在AQS上包装了一下而已.本文也是基于您在有AQS的相关知识基础上,进行讲解 ...
- 深入浅出Mysql索引
索引的出现其实就是为了提高数据查询的效率,就像书的目录一样. 索引模型有三种常见.也比较简单的数据结构分别是哈希表.有序数组和搜索树. 哈希表 哈希表是一种以键 - 值(key-value)存储数据的 ...
- 【PAT】1014. 福尔摩斯的约会 (20)
1014. 福尔摩斯的约会 (20) 大侦探福尔摩斯接到一张奇怪的字条:“我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hy ...
- git的使用总结【干货·转载】
源文地址:https://juejin.im/post/5a54386af265da3e3b7a6317 摘抄: 版本树 / graph / network 干净简洁清晰 提交信息明确 易维护易读 举 ...
- list 往指定的下标插入元素
list 往指定的下标插入元素 import java.util.*; public class ListExample{ public static void main(String[] args) ...
- thinkphp5.0URL访问
URL设计 ThinkPHP5.0在没有启用路由的情况下典型的URL访问规则是: http://serverName/index.php(或者其它应用入口文件)/模块/控制器/操作/[参数名/参数值. ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)G - The heap of socks
题目描述 BSD is a lazy boy. He doesn't want to wash his socks, but he will have a data structure called ...