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的更多相关文章

  1. hdu 4784 Dinner Coming Soon(spfa + 优先队列)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4784 思路:建图,对于同一个universe来说,就按题目给的条件相连,对于相邻的universe,连 ...

  2. The 2013 ACMICPC Asia Regional Chengdu

    还有19天出发北京站,今年北京站的出题方是上交,去年他们出的成都现场的赛题,首先复盘一下. 去年的成都是我经历的第一次现场赛,也是近距离第一次见到了CLJ的真人,最后也是被虐惨了,那时候是声闻大神带着 ...

  3. 怒刷DP之 HDU 1029

    Ignatius and the Princess IV Time Limit:1000MS     Memory Limit:32767KB     64bit IO Format:%I64d &a ...

  4. 【并查集专题】【HDU】

    PS:做到第四题才发现 2,3题的路径压缩等于没写 How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  5. HDU 1213 How Many Tables(模板——并查集)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1213 Problem Description Today is Ignatius' birthday ...

  6. 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 ...

  7. HDU 2255.奔小康赚大钱 最大权匹配

    奔小康赚大钱 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  8. HDU 1213 - How Many Tables - [并查集模板题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 Today is Ignatius' birthday. He invites a lot of ...

  9. HDU 3045 - Picnic Cows - [斜率DP]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3045 It’s summer vocation now. After tedious milking, ...

随机推荐

  1. c++ 简单的词法分析

    scanner.h #include<iostream> #include<fstream> #include<string> using namespace st ...

  2. [LeetCode]题解(python):106-Construct Binary Tree from Inorder and Postorder Traversal

    题目来源: https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/ 题意分析 ...

  3. QT5程序发布dll依赖

    QT5 发布程序,太庞大了,QT4下,基本的也就20M左右 platforms目录是 对应X:\Qt\Qt5.3.2\5.3\mingw482_32\plugins\platforms 下的qmini ...

  4. mget 同时获取

    mget 同时获取: http://192.168.32.81:9200/ _mget POST { "docs" :[ { "_index":"li ...

  5. weblogic的ejb远程调用

    这是一篇对EJB远程调用的简单范例.      1.环境:win7  + weblogic 12c + myeclipse8.5      2.目的:实现在myeclispe中对weblogic中EJ ...

  6. 【翻译自mos文章】oracle支持在RDBMS HOME 下的 符号链接( Symbolic Links)吗?

    oracle支持在RDBMS HOME 下的 符号链接( Symbolic Links)吗? 參考原文: Does Oracle support Symbolic Links in the RDBMS ...

  7. [译]Stairway to Integration Services Level 11 - 日志配置

    介绍 在前一个章节我们讨论了事先行为,分享了如何操作默认的行为和时间冒泡,并且介绍了父子模型. 本文中,我们会配置SSIS日志. 进行简单及高级日志配置,存储,和检索的实验.并且生成自定义日志信息. ...

  8. git和GItHub的区别

    git是一个版本控制工具.github是一个用git做版本控制的项目托管平台. 这有点类似于Wordpress和Wordpress.com的关系,前者是一个任何人都可以用的免费博客系统,后者是一个平台 ...

  9. ASP.NET MVC5 学习笔记-2 Razor

    1. Razor @*注释*@ 你在用 @Request.Browser.Browser, 发送邮件给support@qq.com, 转义@@qq @{ var amounts = new List& ...

  10. Chromium如何显示Web页面

    Displaying A Web Page In Chrome 概念化的应用分层 参见原文档:http://goo.gl/MsEJX 每一个box代表一个抽象层.下层不依赖于上层. WebKit:渲染 ...