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. KVC, KVO 实现原理

    Key-Value Coding: 键值编码 (KVC) 方法调用: // 对象属性 // 类似: Person -> name setValue: forKey: // 对象的属性或者 属性的 ...

  2. 005_linux下logrotate 配置和理解

    对于Linux 的系统安全来说,日志文件是极其重要的工具.系统管理员可以使用logrotate 程序用来管理系统中的最新的事件,对于Linux 的系统安全来说,日志文件是极其重要的工具.系统管理员可以 ...

  3. [转载]FFmpeg完美入门[2] - FFmpeg参数说明

     1 通用选项 -L license -h 帮助 -fromats 显示可用的格式,编解码的,协议的. -f fmt 强迫采用格式fmt -i filename 输入文件 -y 覆盖输出文件 -t d ...

  4. rds 与mysql 进行主从同步

    .rds上默认会有server-****,只需要配置从数据库: .从数据库的配置流程: .[mysqld] log-bin = mysql-bin-changelog #要和主库中的名字一样 rela ...

  5. 搜索关键词智能提示suggestion

    转载自:stormbjm的专栏 题目详情:百度搜索框中,输入“北京”,搜索框下面会以北京为前缀,展示“北京爱情故事”.“北京公交”.“北京医院”等等搜索词,输入“结构之”,会提示“结构之法”,“结构之 ...

  6. sharepoint2013搜索

    参考http://www.cnblogs.com/jianyus/p/3272692.html 最小权限http://www.cnblogs.com/awpatp/archive/2011/08/16 ...

  7. java EE : http 协议之请求报文、响应报文

    1 HTTP协议特点 1)客户端->服务端(请求request)有三部份 a)请求行 b)请求头 c)请求的内容,如果没有,就是空白字符 2)服务端->客户端(响应response)有三部 ...

  8. [转]基于Protel DXP软件的PCB高级编辑技巧大全

    来源:基于Protel DXP软件的PCB高级编辑技巧大全 一.放置坐标指示 放置坐标指示可以显示出PCB板上任何一点的坐标位置. 启用放置坐标的方法如下:从主菜单中执行命令 Place/Coordi ...

  9. poj1475 Pushing Boxes(BFS)

    题目链接 http://poj.org/problem?id=1475 题意 推箱子游戏.输入迷宫.箱子的位置.人的位置.目标位置,求人是否能把箱子推到目标位置,若能则输出推的最少的路径,如果有多条步 ...

  10. Webpack, VSCode 和 Babel 组件模块导入别名

    很多时候我们使用别人的库,都是通过 npm install,再简单的引入,就可以使用了.     1 2 import React from 'react' import { connect } fr ...