HDU 4114 Disney's FastPass Time
来源:互联网 发布:喷涂机器人及软件编程 编辑:程序博客网 时间:2024/06/05 19:17
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?
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 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.
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
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
阅读全文
1 0
- HDU 4114 Disney's FastPass Time
- hdu 4114 Disney's FastPass
- HDU Disney's FastPass
- HDU 4114 Disney's FastPass(状压dp)
- hdu 4114 Disney's FastPass 状压dp
- Hdu 4114 Disney's FastPass(状压dp)
- HDU 4114 Disney's FastPass(floyd+状态压缩DP)
- hdu 4114 Disney's FastPass 状压dp+floyd
- hdu4114.Disney's FastPass
- hdu Disney's FastPass(状态压缩dp)
- HDU Disney's FastPass(状态压缩DP)
- HDU4114 Disney's FastPass(floyd+状态压缩DP)旅游问题升级(难)
- HDU 2142 - disney
- hdu 2142 disney
- hdu 2142 disney(模拟)
- hdu 1242 disney (map模拟)
- Disney
- Regarding Disney
- string
- HDU 2833 WuKong
- HDU 2433 Travel
- HDU 2482 Transit search
- HDU 3191 How Many Paths Are There
- HDU 4114 Disney's FastPass Time
- 蓝桥杯 历届试题 打印十字图
- BrnShop开源网上商城第二讲:ASP.NET MVC框架
- 历届试题 错误票据
- 之江学院2017ACM 校赛Problem G: qwb去面试
- JDBC2
- HDU 2236 无题II(二分匹配模板题,匈牙利算法)
- HDU 1269 迷宫城堡(强连通模板题)
- HDU 3594 Cactus(仙人掌图模板)