HDU 4114 Disney's FastPass Time

Disney's FastPass

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2403    Accepted Submission(s): 658

Problem 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
The first line contains an integer T(1<=T<=25), 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 P i, T i, FT i,N i, F i,1, F i,2 ... F i,Ni-1, F iNi ,(1 <= P i,N i, F i,j <=N, 0 <= FT i <= T i <= 10^4), which means the ith interested araction is placed at location Pi and there are Ni locations F i,1; F i,2 ... F i,N i 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
Case #1: 53
Case #2: 14
 
  1 #include <iostream>
  2 #include <cstring>
  3 #define N 55
  4 #define inf 0x3fffffff
  5 using namespace std;
  6 int mapp[N][N];
  7 bool vis[N];
  8 int T[N],FT[N],Pass[N],pos[N];
  9 int dis[N][1<<8][1<<8];
 10 int n,m,kk;
 11 void floyd(){
 12     for(int k=1;k<=n;k++){
 13         for(int i=1;i<=n;i++){
 14             if(i==k){
 15                 continue;
 16             }
 17             for(int j=1;j<=n;j++){
 18                 if(j==i||j==k){
 19                     continue;
 20                 }
 21                 mapp[i][j]=min(mapp[i][k]+mapp[k][j],mapp[i][j]);
 22             }
 23         }
 24     }
 25 }
 26 
 27 void init(){
 28     for(int i=1;i<=n;i++){
 29         for(int j=1;j<=n;j++){
 30             mapp[i][j]=inf;
 31         }
 32         mapp[i][i]=0;
 33         for(int j=0;j<(1<<kk);j++){
 34             for(int k=0;k<(1<<kk);k++){
 35                 dis[i][j][k]=inf;
 36             }
 37         }
 38     }
 39     memset(Pass,0,sizeof(Pass));
 40 }
 41 
 42 int solve(){
 43     int ans=inf;
 44     dis[1][0][0]=0;
 45     for(int s1=0;s1<(1<<kk);s1++){
 46         for(int s2=0;s2<(1<<kk);s2++){
 47             for(int i=1;i<=n;i++){
 48                 int now = dis[i][s1][s2];
 49                 if(now==inf){
 50                     continue;
 51                 }
 52                 if(s2==((1<<kk)-1)){
 53                     ans=min(ans,now+mapp[i][1]);
 54                 }
 55                 for(int j=0;j<kk;j++){
 56                     if((s2&(1<<j))==0){
 57                         int &nxt=dis[pos[j]][s1|Pass[pos[j]]][s2^(1<<j)];
 58                         int add=mapp[i][pos[j]];
 59                         if(s1&(1<<j)){
 60                             add+=FT[j];
 61                         }
 62                         else{
 63                             add+=T[j];
 64                         }
 65                         nxt=min(nxt,now+add);
 66                     }
 67                 }
 68                 for(int j=1;j<=n;j++){
 69                     int &nxt=dis[j][s1|Pass[j]][s2];
 70                     int add=mapp[i][j];
 71                     nxt=min(nxt,now+add);
 72                 }
 73             }
 74         }
 75     }
 76     return ans;
 77 }
 78 
 79 int main(int argc, char const *argv[]){
 80     cin.sync_with_stdio(false);
 81     int TT,Case;
 82     int a,b,c;
 83     cin>>TT;
 84     for(Case=1;Case<=TT;Case++){
 85         cin>>n>>m>>kk;
 86         init();
 87         for(int i=0;i<m;i++){
 88             cin>>a>>b>>c;
 89             mapp[a][b]=c;
 90             mapp[b][a]=c;
 91         }
 92         floyd();
 93         for(int i=0;i<kk;i++){
 94             cin>>pos[i]>>T[i]>>FT[i];
 95             cin>>m;
 96             for(int j=0;j<m;j++){
 97                 int num;
 98                 cin>>num;
 99                 Pass[num]|=(1<<i);
100             }
101         }
102         cout<<"Case #"<<Case<<": "<<solve()<<endl;
103     }
104     return 0;
105 }
2017-01-30 17:57:06

转载于:https://www.cnblogs.com/xjh-shin/articles/6358224.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值