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, ...
随机推荐
- PGA与SGA
当用户进程连接到数据库并创建一个对应的会话时,Oracle服务进程会为这个用户专门设置一个PGA区,用来存储这个用户会话的相关内容.当这个用户会话终止时,数据库系统会自动释放这个PAG区所占用的内存. ...
- mongodb 学习初探
1.去mongodb 官方下载 http://www.mongodb.org/downloads 2.下载php的mongodb扩展 http://files.cnblogs.com/lsl8966/ ...
- HDU 1089 A+B for Input-Output Practice (I)
#include <cstdio> int main() { int a,b; while(scanf("%d%d",&a,&b)!=EOF) prin ...
- Phoenix——实现向HBase发送标准SQL语句
写在前面一: 本文总结基于HBase的SQL查询系统--Salesforce phoenix 写在前面二: 环境说明: 一.什么是Phoenix 摘自官网: Phoenix是一个提供hbase的sql ...
- How Many Answers Are Wrong(并查集)
Description TT and FF are ... friends. Uh... very very good friends -________-b FF is a bad boy, he ...
- 「OC」@property @synthesize和id
一.@property @synthesize关键字 这两个关键字是编译器特性,让Xcode可以自动生成getter和setter. (一)@property 关键字 @property 关键字可以自 ...
- php随笔7-thinkphp OA系统 JS 文本框输入实时控制字数
JS: //多行文本输入框剩余字数计算 function checkMaxInput(obj, maxLen) { if (obj == null || obj == undefined || obj ...
- seajs + easyui [转]
* *content seajs+easyui使用 */ /** * 首先来看看在seajs中jquery和jquery插件如何使用 */ 1.jquery.js define(function(re ...
- 安装duetdisplay遇到的问题
1.报错failed to correctly acquire vcredist_x64.exe ifle:CRC error 已经确认了 和墙有关系,通过FQ可以正常安装了. 2.在PAD屏幕上面播 ...
- Cygwin ssh
http://www.evalumation.com/blog/86-cygwin-windows7-sshd