HDU4114 Disney's FastPass (floyd+ State compression DP) Travel issue upgrade (difficult)

Source: Internet
Author: User

Disney ' s FastPassTime limit:20000/10000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2117 Accepted Submission (s): 564


Problem Description
The Disney ' s FastPass is a virtual queuing system created by the Walt Disney Company. First introduced in 1999 (Thugh, a ride reservation system is first introduced in world fairs), Fast-pass allo WS guests to avoid long lines at the attractions on which the system was 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-enjoy any of the attractions. The FastPass is a system allowing from pick up fastpass-tickets in some specific position, and use them at the Correspon Ding facility to avoid long lines. With the help of the FastPass System, one can arrange his/her trips more efficiently.
You are given the map of the whole park, and there is some attractions that is interested in. How to visit all the interested attractions within the shortest time?
Inputthe 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 <=, 0 <= M <= N (N-1)/2; 0 <= K <= 8), Indicatin G The number of locations (starting with 1, and 1 are the only gate of the park where the trip must be started and ended), T He 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 araction is Placed at location Pi and there is Ni locations fi,1; fi,2 ... Fi,ni where 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 this all the locations be connected and there is at most one road between any and locations.
Note that there might is several attrractions at the one location.
Outputfor 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

Source2011 Asia Chengdu Regional Contest

Test instructions: Given a weighted graph (n<=50) and several attractions (k<=8) (each vertex can contain multiple attractions),.. Now I want you to ' swim ' These attractions, ' tour ' the conditions of these attractions are you at this point for a certain time, if you have FastPass, that is, after certain points, then only need to wait for the FT time, otherwise you have to wait t time, ask from point 1th to complete the task and then return to point 1th of the minimum time.

Here's a look at other people's Problem solving report:

Idea, State compression Dp,f[i][mark][j] indicates the current point in J, the 2-in state of the point that has been ' swam ' is I, and the fastpass of the hand has a minimum time of 2 binary for Mark

Then F[i][mark][j] ==> f[i | (1<<P)] [New_mark] [Loc[p]]//P is the next to go to the attraction number, Loc[p] is his position, New_mark is after loc[p] new about the FastPass of the 2 binary state

The same f[i]mark][j][= F[i][new_mark][j ']//To another point, not the most ' travel ' those points, can be thought to go with intent is to take FastPass. If Mark==new_mark, this formula will not affect the result.


#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][s Pa][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; }//Go to the Tourist attractions roll for (int j=1; j<=n; J + +) if (pass[j]>0&&dp[sta][spa|pass[j]][j]>dp[sta][sp    A][I]+MAPT[I][J]) dp[sta][spa|pass[j]][j]=dp[sta][spa][i]+mapt[i][j];    }//Find the answer 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 ()); }}

HDU4114 Disney's FastPass (floyd+ State compression DP) Travel issue upgrade (difficult)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.