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. nmon的安装和使用

    1.下载nmon https://zh.osdn.net/projects/sfnet_nmon/downloads/nmon_x86_64_rhel6/ 2../nmon_x86_64_rhel6 ...

  2. 数据库与sql注入的相关知识

    数据库与sql注入的相关知识 sql语句明显是针对数据库的一种操作,既然想通过sql注入的方法来拿取数据那么就要先了解一下如何的去操作数据库,这方面并不需要对数据库有多么的精通但是如果了解掌握了其中的 ...

  3. SPI最大传输速率【转】

    转自:https://www.silabs.com/community/mcu/8-bit/knowledge-base.entry.html/2017/01/13/spi_-asc0 问题 SPI作 ...

  4. UIScrollViewDelegate 方法调用

    UIScrollViewDelegate 方法调用 /** 设置缩放的View, 初始化完之后调用此方法告诉scrollView 谁可以缩放操作, 然后进行布局 */ func viewForZoom ...

  5. Tutorial 1: Serialization

    转载自:http://www.django-rest-framework.org/tutorial/1-serialization/#tutorial-1-serialization Tutorial ...

  6. 进程一些命令pstree,ps,pstack,top

    1. pstree pstree以树结构显示进程$ pstree -p work | grep adsshd(22669)---bash(22670)---ad_preprocess(4551)-+- ...

  7. golang类型转换小总结

    1. int <--> string 1.1. int --> string str := strconv.Itoa(intVal) 当然,整数转换成字符串还有其他方法,比如 fmt ...

  8. google的面试题(三维动态规划的范例)——(87)Scramble String

    转:http://www.cnblogs.com/easonliu/p/3696135.html 分析:这个问题是google的面试题.由于一个字符串有很多种二叉表示法,貌似很难判断两个字符串是否可以 ...

  9. django rest_framework比较完整的自定义实现样例

    里面有自定义的更新策略, 序列化时,考虑nest及显示. 很有参考意义. 然后,前端,可以考虑用angular.js或vue.js实现. 每次以token进行认证. url.py router = D ...

  10. umask相关内容

    umask权限过滤符新创建的文件的权限为666,即- rw- rw- rw-新创建的目录的权限为777,即d rwxrwxrwx如umask值为0022,后三位022,即 --- -w- -w-上述默 ...