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 ;
}
最新文章
- 工欲善其事,必先利其器 之 WPF篇: 随着开发轨迹来看高效WPF开发的工具和技巧
- 决战JS(二)
- git push.default is unset
- php图片防盗链的小测试
- 安装DotNetCore.1.0.0-VS2015Tools.Preview2失败解决方案
- mysql 导入大数据的秘籍
- 《C++Primer》复习——with C++11 [2]
- android开发 Fragment嵌套调用常见错误
- Js处理数据——前端分页工具
- 面试时如何优雅的谈论OC
- Java GC 日志详解(转)
- Android PopupWindow的使用技巧(转)
- python——函数
- [Luogu 2090]数字对
- PowerShell Empire使用笔记
- mySQL简单操作(一)
- echarts常用方法,legend状态支持两张图片切换(四)
- IE8 margin:0 auto 不能居中显示的问题
- [转载]图解程序员必须掌握的Java常用8大排序算法
- WPF 去除系统窗体边框,自定义移动窗体