Disney's FastPass

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=4114

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

HINT

题意

游戏园里有N个区域,有M条边连接这N个区域,有K个要访问的景点。对于每个景点告诉你这个景点所在的区域,要访问这个景点需要等待一定时间,如果没有 FastPass,等待时间有Ti,否则等待时间为FTi,接下来的Ni,表示有Ni个区域可以得到这个景点的FastPass,问从区域1出发,再回到 区域1所需要的最少时间。

题解:

状态压缩dp

http://blog.csdn.net/shiqi_614/article/details/11265439

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 100
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** int dis[maxn][maxn];
int dp[maxn][<<][<<];
int pas[<<];
int ans;
int t[maxn],ft[maxn],pos[maxn];
int n,m,k;
void init()
{
ans=inf;
memset(dp,0x3f,sizeof(dp));
memset(dis,0x3f,sizeof(dis));
memset(pas,,sizeof(pas));
}
void flyod()
{
for(int k=;k<=n;k++)
{
for(int i=;i<=n;i++)
{
if(i!=k)
for(int j=;j<=n;j++)
{
if(j!=i&&j!=k)
dis[i][j]=min(dis[i][k]+dis[k][j],dis[i][j]);
}
}
}
}
void solve()
{
dp[][][]=;
for(int s1=;s1<(<<k);s1++)
{
for(int s2=;s2<(<<k);s2++)
{
for(int i=;i<=n;i++)
{
int now=dp[i][s1][s2]; if(now==inf) continue; if(s2==((<<k)-)) ans=min(ans,now+dis[i][]); for(int j=;j<k;j++) if((s2&(<<j))==)
{
int &nxt=dp[pos[j]][ s1|pas[ pos[j] ] ][s2^(<<j)]; int add=dis[i][pos[j]];
if(s1&(<<j)) add+=ft[j];
else add+=t[j]; nxt=min(nxt,now+add);
}
for(int j=;j<=n;j++)
{
int &nxt=dp[j][s1|pas[j]][s2];
int add=dis[i][j];
nxt=min(nxt,now+add);
}
}
}
}
//return ans;
}
int main()
{
//freopen("test.txt","r",stdin);
int tt=read();
for(int cas=;cas<=tt;cas++)
{
init(); scanf("%d%d%d",&n,&m,&k);
for(int i=;i<n;i++) dis[i][i]=;
for(int i=;i<m;i++)
{
int a,b,c; scanf("%d%d%d",&a,&b,&c);
dis[a][b]=dis[b][a]=c;
} flyod(); for(int i=;i<k;i++)
{
scanf("%d%d%d",&pos[i],&t[i],&ft[i]);
int num; scanf("%d",&num);
for(int j=;j<num;j++)
{
int tmp; scanf("%d",&tmp);
pas[tmp]|=(<<i);
}
}
solve();
printf("Case #%d: %d\n",cas,ans);
}
}

hdu 4114 Disney's FastPass 状压dp的更多相关文章

  1. HDU 6149 Valley Numer II 状压DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6149 题意:中文题目 解法:状压DP,dp[i][j]代表前i个低点,当前高点状态为j的方案数,然后枚 ...

  2. HDU 5434 Peace small elephant 状压dp+矩阵快速幂

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5434 Peace small elephant  Accepts: 38  Submissions: ...

  3. HDU 1074 Doing Homework(状压DP)

    第一次写博客ORZ…… http://acm.split.hdu.edu.cn/showproblem.php?pid=1074 http://acm.hdu.edu.cn/showproblem.p ...

  4. HDU 4906 Our happy ending (状压DP)

    HDU 4906 Our happy ending pid=4906" style="">题目链接 题意:给定n个数字,每一个数字能够是0-l,要选当中一些数字.然 ...

  5. HDU 1074 Doing Homework (状压dp)

    题意:给你N(<=15)个作业,每个作业有最晚提交时间与需要做的时间,每次只能做一个作业,每个作业超出最晚提交时间一天扣一分 求出扣的最小分数,并输出做作业的顺序.如果有多个最小分数一样的话,则 ...

  6. HDU 4568 Hunter 最短路+状压DP

    题意:给一个n*m的格子,格子中有一些数,如果是正整数则为到此格子的花费,如果为-1表示此格子不可到,现在给k个宝藏的地点(k<=13),求一个人从边界外一点进入整个棋盘,然后拿走所有能拿走的宝 ...

  7. HDU 1074 Doing Homework【状压DP】

    Doing Homework Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he ...

  8. HDU 4899 Hero meet devil (状压DP, DP预处理)

    题意:给你一个基因序列s(只有A,T,C,G四个字符,假设长度为n),问长度为m的基因序列s1中与给定的基因序列LCS是0,1......n的有多少个? 思路:最直接的方法是暴力枚举长度为m的串,然后 ...

  9. HDU 5657 CA Loves Math 状压DP + 枚举

    题意: 给出\(A(2 \leq A \leq 11), n(0 \leq n \leq 10^9), k(1 \leq k \leq 10^9)\). 求区间\([1, A^n]\)中各个数字互不相 ...

随机推荐

  1. 背包DP FOJ 2214

    题目:http://acm.fzu.edu.cn/problem.php?pid=2214 (http://www.fjutacm.com/Problem.jsp?pid=2053) 这题看起来是一题 ...

  2. Skip List(跳跃表)原理详解与实现【转】

    转自:http://dsqiu.iteye.com/blog/1705530 Skip List(跳跃表)原理详解与实现 本文内容框架: §1 Skip List 介绍 §2 Skip List 定义 ...

  3. maven将jar包打如本地仓库命令

    mvn install:install-file -DgroupId=org.apache.maven.plugins -DartifactId=maven-javadoc-plugin -Dvers ...

  4. Linux下通过源码编译安装程序(configure/make/make install的作用,然后在/etc/profile文件里修改PATH环境变量)

    一.程序的组成部分 Linux下程序大都是由以下几部分组成: 二进制文件:也就是可以运行的程序文件 库文件:就是通常我们见到的lib目录下的文件 配置文件:这个不必多说,都知道 帮助文档:通常是我们在 ...

  5. java并发容器

    同步容器将所有对容器状态的访问都串行化,以实现线程安全性.这种方式的缺点是严重降低并发性.Java 5.0提供了多种并发容器来改进同步容器的性能.如ConcurrentHashMap代替同步且基于散列 ...

  6. java版云笔记(五)

    下来是创建笔记本,创建笔记,这个没什么难点和前面是一样的. 创建笔记本 首先点击"+"弹出添加笔记的对话框,然后点击确定按钮创建笔记本. //点击"+"弹出添加 ...

  7. java IntelliJ IDEA 13 注册码 IDEA序列号 License Key

    java IntelliJ IDEA 13 注册码 IDEA序列号 License Key Username: JavaDeveloper@sskaje.me License: 282971-M1NW ...

  8. 458. Poor Pigs

    There are 1000 buckets, one and only one of them contains poison, the rest are filled with water. Th ...

  9. Eclipse的SVN插件与本地SVN客户端关联不上

    问题:当我们用SVN客户端把代码更新到本地,并导入到eclipse之后,却发现我们的SVN插件并没有起作用(没有代码入库.修改等小图标的显示,也没有check in,update等功能菜单).如果我们 ...

  10. pip/conda国内镜像--安装包提速

    对于Python开发用户来讲,PIP安装软件包是家常便饭.但国外的源下载速度实在太慢,浪费时间.而且经常出现下载后安装出错问题.所以把PIP安装源替换成国内镜像,可以大幅提升下载速度,还可以提高安装成 ...