hdu 4114 Disney's FastPass(最短路+状态压缩)
Disney's FastPass
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2336 Accepted Submission(s):
644
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?
indicating the number of test cases.
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.
#X: Y", where X is the test case number (starting with 1) and Y is the minimum
time of the trip.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#define INF 0x3f3f3f3f
#define M
#define N 60
using namespace std;
int n,m,k,ans;
int map[N][N];
int p[N],t[N],ft[N],pass[N];
int dp[<<][<<][N]; void floyd()
{
int i,j,k;
for(k=; k<=n; k++)
for(i=; i<=n; i++)
for(j=; j<=n; j++)
if(map[i][j]>map[i][k]+map[k][j])
map[i][j]=map[i][k]+map[k][j];
} void Get_Dp()
{
int i,j,u,v;
for(i=; i<=(<<k); i++)
for(j=; j<=(<<k); j++)
for(u=; u<=n; u++)
dp[i][j][u]=INF;
dp[][][]=;
for(int state1=; state1<(<<k); state1++)
{
for(int state2=; state2<(<<k); state2++)
{
for(u=; u<=n; u++)
{
if(dp[state1][state2][u]<INF)
{
for(i=; i<k; i++)
{
if(!(state1&(<<i))) ///单独取state1的每一位数字
{
int cost=map[u][p[i]];
if((state2&(<<i))) cost+=ft[i];
else cost+=t[i];
dp[state1|(<<i)][state2|pass[p[i]]][p[i]]=min(dp[state1|(<<i)][state2|pass[p[i]]][p[i]],dp[state1][state2][u]+cost);
}
}
for(v=; v<=n; v++)
{
dp[state1][state2|pass[v]][v]=min(dp[state1][state2|pass[v]][v],dp[state1][state2][u]+map[u][v]);
}
}
}
}
}
ans=INF;
for(i=; i<(<<k); i++)
ans=min(ans,dp[(<<k)-][i][]);
} int main()
{
int i,j,T,cas,num,v;
scanf("%d",&T);
for(cas=; cas<=T; cas++)
{
scanf("%d%d%d",&n,&m,&k);
for(i=; i<=n; i++)
for(j=; j<=n; j++)
if(i==j) map[i][j]=;
else map[i][j]=INF;
int a,b,c;
while(m--)
{
scanf("%d%d%d",&a,&b,&c);
if(map[a][b]>c)
map[a][b]=c,map[b][a]=c;
}
floyd();
memset(pass,,sizeof(pass));
for(i=; i<k; i++)
{
scanf("%d%d%d%d",&p[i],&t[i],&ft[i],&num);
while(num--)
{
scanf("%d",&v);
pass[v]|=(<<i); ///没有进位的加法
}
}
Get_Dp();
printf("Case #%d: %d\n",cas,ans);
}
return ;
}
hdu 4114 Disney's FastPass(最短路+状态压缩)的更多相关文章
- hdu 4114 Disney's FastPass 状压dp
Disney's FastPass Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...
- [hdu P4114] Disney's FastPass
[hdu P4114] Disney's FastPass Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 ...
- Light OJ 1316 A Wedding Party 最短路+状态压缩DP
题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...
- 最短路+状态压缩dp(旅行商问题)hdu-4568-Hunter
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4568 题目大意: 给一个矩阵 n*m (n m<=200),方格里如果是0~9表示通过它时要花 ...
- HDU 3605:Escape(最大流+状态压缩)
http://acm.hdu.edu.cn/showproblem.php?pid=3605 题意:有n个人要去到m个星球上,这n个人每个人对m个星球有一个选择,即愿不愿意去,"Y" ...
- HDU 2809 God of War(DP + 状态压缩)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2809 题目大意:给出战神吕布的初始攻击力ATI.防御力DEF.生命值HP.每升一级增加的攻击力In_A ...
- POJ 3311 Hie with the Pie (BFS+最短路+状态压缩)
题意:类似于TSP问题,只是每个点可以走多次,求回到起点的最短距离(起点为点0). 分析:状态压缩,先预处理各点之间的最短路,然后sum[i][buff]表示在i点,状态为buff时所耗时...... ...
- hdu 4352 XHXJ's LIS 数位dp+状态压缩
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4352 XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others ...
- hdu - 1429 胜利大逃亡(续) (bfs状态压缩)
http://acm.hdu.edu.cn/showproblem.php?pid=1429 终于开始能够做状态压缩的题了,虽然这只是状态压缩里面一道很简单的题. 状态压缩就是用二进制的思想来表示状态 ...
随机推荐
- nginx 封ip
封ip段 例如ip为:xx.xx.xx.xx 全封:0.0.0.0/0 封后三段:xx.0.0.0/8 封后两段:xx.xx.0.0/16 封最后一段:xx.xx.xx.0/24
- javax.el.PropertyNotFoundException: Property 'studentAge' not found on type com.hs.model.StudentModel
mi明明已经把这个字段重构了,为啥还这样提示呢?整个工程全部 查找也找不到这个字段了啊
- java笔记之split
Java split()用法 特殊情况有 * ^ : | . \ 一.单个符号作为分隔符 String address="上海\上海市|闵行区\吴中路"; String[] sp ...
- MySQL数据库起步 关于数据库的基本操作(更新中...)
mysql的基本操作 连接指定的服务器(需要服务器开启3306端口) mysql -h ip地址 -P 端口号 -u 账号 -p 密码 删除游客模式 mysql -h ip地址 -P 端口号 -u 账 ...
- 洛谷P1052 过河
P1052 过河 题目描述 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子上. 由于桥的长度和青蛙一次跳过的距离都是正整数,我们可以把独木桥上青 ...
- 阿里云杨敬宇:5G时代,边缘计算将发挥更大价值
“5G时代,边缘计算将发挥更大价值.”3月8日,阿里云边缘计算技术负责人杨敬宇向媒体表示,边缘计算作为5G时代的一项关键技术,未来将成为不可或缺的基础设施之一. 5G时代万物智联将真正成为现实,但对计 ...
- web前端学习(三)css学习笔记部分(6)-- 选择器详解
9.选择器详解 9.1 属性选择器 CSS3 属性选择器,在 CSS3 中,追加了三个属性选择器分别为:[att*=val].[att^=val]和[att$=val],使得属性选择器有了通配符的概 ...
- 用gradle4.4转化spring,发现依赖包integration-0.9.15.jar已经不在
用gradle4.4转化spring,发现依赖包integration-0.9.15.jar已经不在仓库了,应该怎么解决? 解决办法如下: 1 修改build.gradle文件,将id " ...
- Spring_Bean的作用域---和使用外部属性文件
<!-- 使用 bean的scope属性来配置bean的作用域 singleton:默认值.容器初始时创建bean实例,在整个容器的生命周期内只创建这一个bean单例 prototype:原型的 ...
- AS2.2使用CMake方式进行JNI/NDK开发
之前写过一篇比较水的文章Android手机控制电脑撸出HelloWorld 里面用到了JNI/NDK技术. 这篇文章给大家介绍下JNI/NDK开发.采用的是Android Studio2.2开发环境, ...