HDU4114 Disney's FastPass(floyd+状态压缩DP)旅游问题升级(难)
来源:互联网 发布:ubuntu可以用来做什么 编辑:程序博客网 时间:2024/05/23 19:14
Disney's FastPass
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2117 Accepted Submission(s): 564
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 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
24 5 21 2 82 3 43 4 194 1 62 4 72 25 18 1 34 12 6 1 34 6 21 2 51 4 43 1 13 2 13 4 12 4 102 8 3 1 44 8 3 1 2
Sample Output
Case #1: 53Case #2: 14
Source
2011 Asia ChengDu Regional Contest
题意:给定一个带权无向图(n<=50)和图中若干个景点(k<=8)(每个顶点可包含多个景点),..现在要你‘游’这些景点,‘游’过这些景点的条件是你在这个点等上了一定的时间,如果你有fastpass,也就是经过某些点,那么只需要等FT的时间,否则要等T的时间,问从1号点出发完成任务再回到1号点的最少时间。
下面是看了别的人解题报告:
思路,状态压缩dp,f[i][mark][j]表示当前在j这个点,已经‘游’过的点的2进制状态为i,手上有fastpass的2进制为mark的最少时间
则f[i][mark][j] ==> f[i | (1<<p)][new_mark][loc[p]] // p是下一个要去的景点号,loc[p]是他的位置,new_mark是经过loc[p]后新的关于fastpass的2进制状态
同理f[i]mark][j][ => f[i][new_mark][j'] // 往另外一个点走,不是最‘游’那些点,可以认为有意图地去是拿fastpass。如果mark==new_mark, 这个式子有没有都不影响结果。
#include<stdio.h>#include<queue>#include<vector>using namespace std;const int N =55;const int inf = 999999999;#define mov(a) (1<<(a))int mapt[N][N],dp[1<<9][1<<9][N],nint P[N],T[N],FT[N],pass[N],k;void init(){ for(int j=0; j<mov(k); j++) for(int e=0; e<mov(k); e++) for(int i=0; i<=n; i++) dp[j][e][i]=inf; for(int i=0; i<=n; i++) { pass[i]=0; for(int j=0; j<=n; j++) mapt[i][j]=inf; mapt[i][i]=0; }}void floyd(){ for(int e=1; e<=n; e++) for(int i=1; i<=n; i++) if(e!=i) { for(int j=1; j<=n; j++) if(i!=j&&e!=j&&mapt[i][j]>mapt[i][e]+mapt[e][j]) mapt[i][j]=mapt[i][e]+mapt[e][j]; }}int DP(){ dp[0][0][1]=0; for(int sta=0; sta<mov(k); sta++) for(int spa=0; spa<mov(k); spa++) for(int i=1; i<=n; i++) if(dp[sta][spa][i]!=inf) { for(int e=0; e<k; e++) if((sta&mov(e))==0) { int cost=((spa|pass[P[e]])&mov(e))>0?FT[e]:T[e]; if(dp[sta|mov(e)][spa|pass[P[e]]][P[e]]>dp[sta][spa][i]+mapt[i][P[e]]+cost) dp[sta|mov(e)][spa|pass[P[e]]][P[e]]=dp[sta][spa][i]+mapt[i][P[e]]+cost; } //去找旅游景点卷 for(int j=1; j<=n; j++) if(pass[j]>0&&dp[sta][spa|pass[j]][j]>dp[sta][spa][i]+mapt[i][j]) dp[sta][spa|pass[j]][j]=dp[sta][spa][i]+mapt[i][j]; } //找答案 int ans=inf; for(int spa=0; spa<mov(k); spa++) for(int i=1;i<=n;i++) if(ans>dp[mov(k)-1][spa][i]+mapt[i][1]) ans=dp[mov(k)-1][spa][i]+mapt[i][1]; return ans;}int main(){ int t,cas=0,m,a,b,c; scanf("%d",&t); while(t--) { scanf("%d%d%d",&n,&m,&k); init(); while(m--) { scanf("%d%d%d",&a,&b,&c); if(mapt[a][b]>c) mapt[a][b]=mapt[b][a]=c; } for(int i=0;i<k;i++) { scanf("%d%d%d%d",&P[i],&T[i],&FT[i],&m); while(m--) { scanf("%d",&a); pass[a]|=1<<i; } } floyd(); printf("Case #%d: %d\n",++cas,DP()); }}
0 0
- HDU4114 Disney's FastPass(floyd+状态压缩DP)旅游问题升级(难)
- HDU 4114 Disney's FastPass(floyd+状态压缩DP)
- hdu Disney's FastPass(状态压缩dp)
- HDU Disney's FastPass(状态压缩DP)
- hdu4114.Disney's FastPass
- Hdu 4114 Disney's FastPass(状压dp)
- hdu 4114 Disney's FastPass 状压dp+floyd
- HDU 4114 Disney's FastPass(状压dp)
- hdu 4114 Disney's FastPass 状压dp
- HDU Disney's FastPass
- hdu 4114 Disney's FastPass
- HDU4114-floyd+ 状压dp
- hdu 5418(状态压缩dp+Floyd)
- HDU 4114 Disney's FastPass Time
- POJ3311(状态压缩DP+Floyd)
- 【POJ2411】Mondriaan's Dream-状态压缩DP(插头DP?)
- HDU 5418 Victor and World(状态压缩路径DP或+floyd 两种方法 求 玈行商问题)经典
- nyoj-1182旅游【三进制状态压缩dp】
- 求周期(周期内无相同数字)
- QT 打开文件对话框总结
- 看数据结构写代码(50)伙伴系统
- 查找api函数地址
- POJ1611(并查集)
- HDU4114 Disney's FastPass(floyd+状态压缩DP)旅游问题升级(难)
- Step into MongoDB - 03 - Database & Collection & Document
- 基金都快放假吗,可感受到
- bzoj 3993: [Sdoi2015]星际战争
- 图片随机显示器(C#)
- openstack学习笔记----KVM
- nodejs笔记
- JSP Xxx cannot be resolved to a type
- Ubuntu的复制粘贴操作及常用快捷键