[hdu P4114] Disney's FastPass

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

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 araction 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

Source
2011 Asia ChengDu Regional Contest

好题啊!只是刚开始一直被题意杀,样例都不知道为什么是这样。

好吧,那就解释一下题意吧。

一个人在一个城市里游玩,共n个景区,m条景区间相连的双向道路,还有k个景点,在n个景区里面(每个景区可能有多个或没有景点)。

然后给出一些景区间互达所需时间(就是边权),然后没有重边。

再给出每个景点的信息,包含:

这个景点在哪个景区里面,然后涉及到一个FastPass的问题。

就是说,如果你在游玩这个景点前有了这个景区的FastPass(注意是游玩而不是经过),那么只需要FTi的时间排队等候(就是游览自身所需时间),否则需要Ti的时间。

还有一点,就是FastPass相当于一张永久票,得到了就不会丢掉,并且同一时刻可以拿好几张。

所以样例二的解释就是,1-->3-->2(经过,并拿到4的票)-->4(游玩,并拿到2的票)-->3-->1。

总用时为(1)+(1)+(1+1+3)+(1+1+3)+(1+1)。

好,这下题意应该算是挺清楚了。我们来想做法。

在被题意杀之前我就写了个状压,然后GG了。

但每错,k那么小,显然是状压的料!

但首先,我们先要预处理出任意两个景区之间的最短路径,这是个贪心的思想,没有问题。

然后,我们设一个状态dp[s1][s2][i]。s1是已游览的点二进制集(0<=s1<1<<k),s2是手上拥有的FastPass的点二进制集,i代表目前所在的点。

显然初始状态dp[0][0][1]=0,其他=inf。最终结果是dp[(1<<k)-1][i][1](0<=i<1<<k)。

然后我们来考虑方程。一般状压dp,用当前状态更新后继状态写的比较多,比较方便。

然后我们分两种情况:

1.下一个访问的景区同时要被参观景点-->dp[s1|(1<<j)][s2|own[b[j]]][b[j]]=min(dp[s1][s2][i])。

其中own[i]表示景区i拥有的某些景点的FastPass,这些节点组成二进制集,b[i]表示景点i所在的景区。

2.下一个访问的景区不被参观景点-->dp[s1][s2|own[j]][j]=min(dp[s1][s2][i])。

然后,算一下复杂度,O(T*(1<<8)*(1<<8)*(n^2)),像是要T的样子,但事实上没有满,测出来跑了2000ms,还可以。

code:

 %:pragma GCC optimize()
 #include<bits/stdc++.h>
 #define ms(a,x) memset(a,x,sizeof a)
 using namespace std;
 ,S=,inf=0x3c3c3c3c;
 int n,m,t,ans,f[N][N],b[N],t1[N],t2[N],cn[N],dp[S][S][N];
 inline int read() {
     ; char ch=getchar();
     ') ch=getchar();
     +ch-',ch=getchar();
     return x;
 }
 inline int bitcnt(int s) {
     ;
     )+bitcnt(s>>);
 }
 inline void upd(int &x,int y) {if (x>y) x=y;}
 int main() {
     ; cs<=T; cs++) {
         n=read(),m=read(),t=read(),ms(f,),ms(cn,);
         ,x,y,z; i<=m; i++) {
             x=read(),y=read(),z=read();
             z=min(z,f[x][y]),f[x][y]=f[y][x]=z;
         }
         ; i<=n; i++) f[i][i]=;
         ; k<=n; k++)
             ; i<=n; i++)
                 ; j<=n; j++) f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
         ,x,y; i<t; i++) {
             b[i]=read(),t1[i]=read(),t2[i]=read(),x=read();
             ; j<=x; j++) y=read(),cn[y]|=(<<i);
         }
         ms(dp,),dp[][][]=;
         ; s1<(<<t); s1++)
             ; s2<(<<t); s2++)
                 ; i<=n; i++) if (dp[s1][s2][i]<inf) {
                     ,c; j<t; j++) <<j))==) {
                         c=s2&(<<j)?t2[j]:t1[j],c+=f[i][b[j]];
                         upd(dp[s1|(<<j)][s2|cn[b[j]]][b[j]],dp[s1][s2][i]+c);
                     }
                     ; j<=n; j++)
                         upd(dp[s1][s2|cn[j]][j],dp[s1][s2][i]+f[i][j]);
                 }
         ans=inf;
         ; i<(<<t); i++) upd(ans,dp[(<<t)-][i][]);
         printf("Case #%d: %d\n",cs,ans);
     }
     ;
 }

[hdu P4114] Disney's FastPass的更多相关文章

  1. hdu 4114 Disney's FastPass 状压dp

    Disney's FastPass Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...

  2. hdu 4114 Disney's FastPass(最短路+状态压缩)

    Disney's FastPass Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  3. [GodLove]Wine93 Tarining Round #4

    比赛链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=44903#overview 题目来源: 2011 Asia ChengDu R ...

  4. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  5. hdu图论题目分类

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  6. HDU图论题单

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  7. 【转】最短路&差分约束题集

    转自:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★254 ...

  8. 【HDOJ图论题集】【转】

    =============================以下是最小生成树+并查集====================================== [HDU] How Many Table ...

  9. 最短路&查分约束

    [HDU] 1548 A strange lift 根蒂根基最短路(或bfs)★ 2544 最短路 根蒂根基最短路★ 3790 最短路径题目 根蒂根基最短路★ 2066 一小我的观光 根蒂根基最短路( ...

随机推荐

  1. python练习题-day11

    1.编写装饰器,为多个函数加上认证的功能(用户的账号密码来源于文件), 要求:登录成功一次,后续的函数都无需再输入用户名和密码 flag=False def wrapper(fun): def inn ...

  2. 《linux就该这么学》开课,linux之路新开始

    今天开课第一天,虽然不会有实实在在的干货知识,只要是了解一下linux和认证.所以我也简单说一下我的linux之路 linux我是无意接触到的,因为工作,我接触的服务器较多,但是都是linux系统,记 ...

  3. #WEB安全基础 : HTTP协议 | 0x6 初识HTTP报文

    欢迎来到HTTP最精彩的部分 请注意:应用HTTP协议时,必定有一方担任客户端,另一方担任服务器 客户端向服务器发出请求,服务器向客户端返回响应 下面是一个请求与相应的例子: 请求: GET /ind ...

  4. python locust 性能测试:locust 参数化(list) ---循环取数据,数据可重复使用

    from locust import TaskSet, task, HttpLocust class UserBehavior(TaskSet): def on_start(self): # 当模拟用 ...

  5. JVM探秘2--详解内存溢出OutOfMemoryError异常

    JVM运行时内存被划分成多个区域,而除了程序计数器之外,其他几个区都会出现OutOfMemoryError异常,主要原因就是对应内存区域的内存不足以再分配内存,一般要么是内存泄漏了要么就是内存参数设置 ...

  6. 专题8:javascript中事件

    一.事件流 1.1 事件冒泡 冒泡型事件:事件按照从最特定的事件目标到最不特定的事件目标的顺序逐一触发: 注意:各个浏览器在处理<html>标记级别的事件时顺序有出入,因此无论任何情况,都 ...

  7. element table 二次封装 父子组件传值 组件通信

    新建一个组件(即子组件)table.vue 子组件编辑内容如下图所示 子组件通过props获取父组件传递过来的参数,如下图所示,type指明传递到子组件的数据类型,default指定默认值,一般不给 ...

  8. hisi 生产固件生成

    生产需求,需要16M bin 文件 给 spi flash烧写 一般有三种方式 1.把文件都导入flash,拆了flash 用烧录器读取,比较可靠! 2.编译时候合并,需要在空余地方填充0xFF拼成1 ...

  9. sed 正则的一个小问题

    有一段类似以下的文本 aabbccc test[3307]112323553-66778tp aooppx69tp ooppsg aabbccc test[3307]1127233-6674tp bo ...

  10. centos7 keepalived 配置高可用

    ! Configuration File for keepalived global_defs { notification_email { xaioqiang.he@xinboxinmo.com } ...