hdu 4114 Disney's FastPass 状压dp
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
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 araction 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
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的更多相关文章
- HDU 6149 Valley Numer II 状压DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6149 题意:中文题目 解法:状压DP,dp[i][j]代表前i个低点,当前高点状态为j的方案数,然后枚 ...
- HDU 5434 Peace small elephant 状压dp+矩阵快速幂
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5434 Peace small elephant Accepts: 38 Submissions: ...
- HDU 1074 Doing Homework(状压DP)
第一次写博客ORZ…… http://acm.split.hdu.edu.cn/showproblem.php?pid=1074 http://acm.hdu.edu.cn/showproblem.p ...
- HDU 4906 Our happy ending (状压DP)
HDU 4906 Our happy ending pid=4906" style="">题目链接 题意:给定n个数字,每一个数字能够是0-l,要选当中一些数字.然 ...
- HDU 1074 Doing Homework (状压dp)
题意:给你N(<=15)个作业,每个作业有最晚提交时间与需要做的时间,每次只能做一个作业,每个作业超出最晚提交时间一天扣一分 求出扣的最小分数,并输出做作业的顺序.如果有多个最小分数一样的话,则 ...
- HDU 4568 Hunter 最短路+状压DP
题意:给一个n*m的格子,格子中有一些数,如果是正整数则为到此格子的花费,如果为-1表示此格子不可到,现在给k个宝藏的地点(k<=13),求一个人从边界外一点进入整个棋盘,然后拿走所有能拿走的宝 ...
- HDU 1074 Doing Homework【状压DP】
Doing Homework Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he ...
- HDU 4899 Hero meet devil (状压DP, DP预处理)
题意:给你一个基因序列s(只有A,T,C,G四个字符,假设长度为n),问长度为m的基因序列s1中与给定的基因序列LCS是0,1......n的有多少个? 思路:最直接的方法是暴力枚举长度为m的串,然后 ...
- 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]\)中各个数字互不相 ...
随机推荐
- 背包DP FOJ 2214
题目:http://acm.fzu.edu.cn/problem.php?pid=2214 (http://www.fjutacm.com/Problem.jsp?pid=2053) 这题看起来是一题 ...
- webgote的例子(4)Sql注入(SelectGET)
SQL Injection (Select/GET) 本章内容 (查询显示中要注意的错误) 这里面我们看一下 movie的数值,选择表单中的当我们选择的二个的时候 move的值也变成了第二个,选择表单 ...
- 如何在LINUX中开机、登陆、退出、定时、定期自动运行程序
1.开机启动时自动运行程序 Linux加载后, 它将初始化硬件和设备驱动, 然后运行第一个进程init.init根据配置文件继续引导过程,启动其它进程.通常情况下,修改放置在 /etc/rc或 /et ...
- 4B/5B编码原理
4B/5B编码原理 什么是4B/5B编码? 4B/5B编码是百兆以太网(即快速以太网)中线路层编码类型之一,就是用5bit的二进制数来表示4bit二进制数,映射方式如下表所示: 为什么要进行4B/5B ...
- html的loadrunner脚本2
Action(){ char buf[1911]; //¶¨Òå×Ö·ûÊý×飬Ö÷ÒªÓÃÓÚдÈëXML±¨Îĵ½»º³åÇø char str_Body[4086]; //³Ð½Ó±¨Î ...
- loadrunner 测试问题汇总
1.关于Error -27791: Error -27790:Error -27740: 错误如下: Action.c(198): Error -27791: Server ...
- Java杂知识汇总(自己积累的)
[前提] 接下来,可能需要开始学习Java了,所以现在将前辈们传递给我的经验都记录下来,免得再次问他们. [积累] 1. 关于重启Tomcat服务器: 当在开发过程中, | 修改Java代码 -- 需 ...
- ueditor 编辑器上传到服务器后图片上传不能正常使用
网站集成ueditor编辑器后在本地能正常使用,上传到服务器上后,图片上传功能提示:后端配置项没有正常加载,上传插件不能正常使用.且单个图片上传图标是灰色的不能点击. 相信遇到这个问题的同学是很多的吧 ...
- go接口及嵌入类型例子
书上看的.慢慢领会.. package main import ( "fmt" ) type notifier interface { notify() } type user s ...
- JS函数练习题
第一题:封装一个输入半径求圆的面积的函数 var banJing = parseInt(prompt("请输入圆的半径")); var x = m(banJing); alert( ...