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, ...
随机推荐
- ORACLE备份手记
嘛的,最近一直写EPOLL的游戏服务端搞的头晕,BOSS说了要备份ORACLE,由于DBA离职了,搞这个事情搞的很蛋疼,关掉实例后备份数据库各种连接不到实例,本来今晚要完成泡泡堂游戏的DX版的,郁闷 ...
- tmod命令
tmod ./tpl --debug --no-watch --output ./tplbuild
- Latex调整行距
修改行间距的方法: \usepackage{setspace}%使用间距宏包 \begin{document} \begin{spacing}{2.0}%%行间距变为double-space 双倍行距 ...
- linux和windows的文件互传
Linux →→→Windows 1.使用secureCRT:下载文件只需在shell终端仿真器中输入命令"sz 文件名",即可利用Zmodem将文件下载到本地某目录下. 2. s ...
- web开发注意的一些事
js命名不要包含"-",在chrome浏览器是测试发现,如果文件包含"-",即使指定js本地缓存了,还会向服务器发送请求. cookie path 区分大小写
- Windows Azure 网站自愈
编辑人员注释:本文章由 Windows Azure 网站团队的项目经理Apurva Joshi 撰写. 您有多少次在半夜被叫醒去解决一个仅需重新启动网站即可解决的问题?要是可以自动检测一些状况并自动恢 ...
- 软碟通UltraISO 9.65.3237官方注册版
UltraISO软碟通是一款功能强大.方便实用.老牌优秀的光盘映像文件制作/编辑/转换工具:可直接编辑ISO文件,从ISO中提取文件和目录:也可从CD – ROM制作光盘映像或者将硬盘上的文件制作成I ...
- WLAN和WIFI的区别
在刚刚为大家介绍的wifi上网是什么意思?文章中为大家介绍了什么wifi无线上网,但大家可能会有这样的疑问,听说最多的应该是WLAN无线上网,很多笔记本电脑使用的都是WLAN无线上网,那么wlan和w ...
- 简简单单C#爬虫小计
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net ...
- linux基本命令-注销、关机、重起
链接地址:http://blog.163.com/bhao_home/blog/static/6647763120081202047945/ 一.注销,关机,重启 注销系统的logout命令 1,Lo ...