hdu 4784 Dinner Coming Soon
spfa+优先队列。刚开始只用的spfa,结果tle到死。然后听队友说要用到优先队列,想了想,对时间分层的话的确每一个结点都只进队列一次即可,因为只有大时间才能更新出小时间,然后就wa成shi了。按队友写的改了才过得,好伤心的说,这是好题。。。
附上代码供大家对拍吧。
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#define LL long long
#define CLR(a, b) memset(a, b, sizeof(a))
#define REP(i, n) for(int i = 0; i < n; i ++)
#define FF(i, a, b) for(int i = a; i < b; i ++)
#define FD(i, a, b) for(int i = a; i >= b; i --)
#define swp(a, b) a^=b^=a^=b; using namespace std; struct Node
{
int u, b, vd, t;
Node(){}
Node(int a, int b, int c, int d):u(a), b(b), vd(c), t(d){}
bool operator < (const Node &rhs) const
{
return t < rhs.t;
}
}; struct Edge
{
int u, v, t, m;
Edge(){}
Edge(int a, int b, int c, int d):u(a), v(b), t(c), m(d){}
}E[420]; int fir[220], next[440], tot; void Add_Edge(int u, int v, int t, int m)
{
E[tot] = Edge(u, v, t, m);
next[tot] = fir[u]; fir[u] = tot ++;
} int dp[110][6][7][220];
bool vis[110][6][7][220];
int p[110][7];
int N, M, B, K, R, T; priority_queue<Node>q; void relax(int u, int b, int vd, int t, int val)
{
if ((u == 1 || u == N) && vd != 0) return ;
if(dp[u][b][vd][t] < val)
{
dp[u][b][vd][t] = val;
if(!vis[u][b][vd][t])
{
Node w = Node(u, b, vd, t);
q.push(w);
vis[u][b][vd][t] = true;
}
}
} void spfa()
{
int u, v, m, t,vd, b;
Node a = Node(1, 0, 0, T);
CLR(dp, -1);CLR(vis, false);
dp[1][0][0][T] = R;
vis[1][0][0][T] = true;
q.push(a);
while(!q.empty())
{
a = q.top();q.pop();
u = a.u;b = a.b;vd = a.vd;t = a.t;
if(u == N) continue;
if(t > 0)
{
int val = dp[u][b][vd][t];
relax(u, b, (vd + 1) % K, t - 1, val);
if(p[u][vd] != -1)
{
if(b > 0)
{
relax(u, b - 1, (vd + 1) % K, t - 1, val + p[u][vd]);
}
if(b < B && val >= p[u][vd])
{
relax(u, b + 1, (vd + 1) % K, t - 1, val - p[u][vd]);
}
}
}
for(int i = fir[u]; ~i; i = next[i])
{
int tmp = t - E[i].t;
if(tmp < 0) continue;
v = E[i].v;
int val = dp[u][b][vd][t] - E[i].m;
if(val < 0) continue;
relax(v, b, vd, tmp, val);
if(p[u][vd] != -1)
{
if(b > 0)
{
relax(v, b - 1, vd, tmp, val + p[u][vd]);
}
if(b < B && val >= p[u][vd])
{
relax(v, b + 1, vd, tmp, val - p[u][vd]);
}
}
}
}
} int main()
{
int Time, cas = 1;
scanf("%d", &Time);
while(Time --)
{
scanf("%d%d%d%d%d%d", &N, &M, &B, &K, &R, &T);
for(int i = 0; i < K; i ++)
{
for(int j = 1; j <= N; j ++)
{
scanf("%d", &p[j][i]);
}
}
CLR(fir, -1);tot = 0;
int u, v, t, m;
for(int i = 0; i < M; i ++)
{
scanf("%d%d%d%d", &u, &v, &t, &m);
Add_Edge(u, v, t, m);
}
spfa();
int ans = -1;
for(int i = 0; i <= B; i ++)
{
for(int j = 0; j <= T; j ++)
{
ans = max(ans, dp[N][i][0][j]);
}
}
if(ans != -1) printf("Case #%d: %d\n", cas ++, ans);
else printf("Case #%d: Forever Alone\n", cas ++);
}
}
hdu 4784 Dinner Coming Soon的更多相关文章
- hdu 4784 Dinner Coming Soon(spfa + 优先队列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4784 思路:建图,对于同一个universe来说,就按题目给的条件相连,对于相邻的universe,连 ...
- The 2013 ACMICPC Asia Regional Chengdu
还有19天出发北京站,今年北京站的出题方是上交,去年他们出的成都现场的赛题,首先复盘一下. 去年的成都是我经历的第一次现场赛,也是近距离第一次见到了CLJ的真人,最后也是被虐惨了,那时候是声闻大神带着 ...
- 怒刷DP之 HDU 1029
Ignatius and the Princess IV Time Limit:1000MS Memory Limit:32767KB 64bit IO Format:%I64d &a ...
- 【并查集专题】【HDU】
PS:做到第四题才发现 2,3题的路径压缩等于没写 How Many Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- HDU 1213 How Many Tables(模板——并查集)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1213 Problem Description Today is Ignatius' birthday ...
- HDU 1029 Ignatius and the Princess IV / HYSBZ(BZOJ) 2456 mode(思维题,~~排序?~~)
HDU 1029 Ignatius and the Princess IV (思维题,排序?) Description "OK, you are not too bad, em... But ...
- HDU 2255.奔小康赚大钱 最大权匹配
奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- HDU 1213 - How Many Tables - [并查集模板题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 Today is Ignatius' birthday. He invites a lot of ...
- HDU 3045 - Picnic Cows - [斜率DP]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3045 It’s summer vocation now. After tedious milking, ...
随机推荐
- 5.7.1.3 Global 对象的属性
Global对象还包含了一些属性,例如,特殊的值undefined.NaN以及Infinity都是Global对象的属性.此外,所有原生引用类型的构造函数,像Object和Function,也都是Gl ...
- objectiveC获取本地时间。
NSDate * date = [NSCalendarDate date]; NSLog(@"%@", date); 日历在IOS里报错,,. NSDateFormatter *f ...
- Protel99se轻松入门:一些高级设置和常用技巧
给PCB补泪滴的具体操作 这里我们可以知道给PCB做覆铜是多么的简单 在PCB中如何找到我们要找的封装 在PCB中如何打印出中空的焊盘(这个功能对于热转印制板比较有用) 如何在PCB文件中加上漂亮的汉 ...
- (C#)Windows Shell 外壳编程系列9 - QueryInfo 扩展提示
原文 (C#)Windows Shell 外壳编程系列9 - QueryInfo 扩展提示 (本系列文章由柠檬的(lc_mtt)原创,转载请注明出处,谢谢-) 接上一节:(C#)Windows She ...
- c++ bitset使用
A bitset is a special container class that is designed to store bits (elements with only two possibl ...
- C++那些库
在C++中,库的地位是非常高的. 基础库 boost“准”标准库 boost库是经过千锤百炼,可移植提供源代码的C++库,作为标准库的后备.跨平台的.有一个大的C++社区支持 Boost中比较著名的库 ...
- 未能加载文件或程序集“DAL”或其他的某一个依赖项,系统找不到指定的文件
针对这个问题我在敲VB.NET机房收费系统的时候总共出现了两次,第一次是在使用反射+抽象工厂的时候出现的,第二次是在使用VS2012自带的打包工具生成可执行文件执行exe文件的时候出现的.具体看下图: ...
- authorization 元素(ASP.NET 设置架构)
authorization 元素(ASP.NET 设置架构) 其他版本 1(共 1)对本文的评价是有帮助 - 评价此主题 [本文档仅供预览,在以后的发行版中可能会发生更改.包含的空白主题用作占位符.] ...
- iOS系统原生二维码条形码扫描
本文讲述如何用系统自带的东东实现二维码扫描的功能:点击当前页面的某个按钮,创建扫描VIEW.细心的小伙伴可以发现 title被改变了,返回按钮被隐藏了.这个代码自己写就行了,与本文关系不大...绿色的 ...
- vim 多文件编辑【超实用】
vim 多文件编辑(偶的linux笔记) http://blog.csdn.net/lcj_cjfykx/article/details/18805721 通过vim打开的每个文件都对应着一个buff ...