HDU 4571 Travel in time(最短路径+DP)(2013 ACM-ICPC长沙赛区全国邀请赛)
Assuming that there are N scenic spots in Changsha, Bob defines a satisfaction value Si to each spot. If he visits this spot, his total satisfaction value will plus Si. Bob hopes that within the limited time T, he can start at spot S, visit some spots selectively, and finally stop at spot E, so that the total satisfaction value can be as large as possible. It's obvious that visiting the spot will also cost some time, suppose that it takes Ci units of time to visit spot i ( 0 <= i < N ).
Always remember, Bob can choose to pass by a spot without visiting it (including S and E), maybe he just want to walk shorter distance for saving time.
Bob also has a special need which is that he will only visit the spot whose satisfaction value is strictly larger than that of which he visited last time. For example, if he has visited a spot whose satisfaction value is 50, he would only visit spot whose satisfaction value is 51 or more then. The paths between the spots are bi-directional, of course.
The first line of each test data contains five integers: N M T S E. N represents the number of spots, 1 < N < 100; M represents the number of paths, 0 < M < 1000; T represents the time limitation, 0 < T <= 300; S means the spot Bob starts from. E indicates the end spot. (0 <= S, E < N)
The second line of the test data contains N integers Ci ( 0 <= Ci <= T ), which means the cost of time if Bob visits the spot i.
The third line also has N integers, which means the satisfaction value Si that can be obtained by visiting the spot i ( 0 <= Si < 100 ).
The next M lines, each line contains three integers u v L, means there is a bi-directional path between spot u and v and it takes L units of time to walk from u to v or from v to u. (0 <= u, v < N, 0 <= L <= T)
The second line contains an integer, which is the greatest satisfaction value.
If Bob can’t reach spot E in T units of time, you should output just a “0” (without quotation marks).
#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
typedef long long LL; const int MAXN = ;
const int MAXE = MAXN * MAXN; int n, m, st, ed, T;
int val[MAXN], vis_c[MAXN];
int mat[MAXN][MAXN]; inline void update_min(int &a, const int &b) {
if(a > b) a = b;
} inline void update_max(int &a, const int &b) {
if(a < b) a = b;
} struct Solve {
int head[MAXN], indeg[MAXN];
int to[MAXE], next[MAXE], cost[MAXE];
int ecnt; void init() {
memset(head, , sizeof(head));
memset(indeg, , sizeof(indeg));
ecnt = ;
} void add_edge(int u, int v, int c) {
++indeg[v];
to[ecnt] = v; cost[ecnt] = c; next[ecnt] = head[u]; head[u] = ecnt++;
} int dp[MAXN][MAXN * ]; int solve() {
memset(dp, -, sizeof(dp));
dp[n][] = ;
queue<int> que; que.push(n);
while(!que.empty()) {
int u = que.front(); que.pop();
for(int i = ; i <= T; ++i) update_max(dp[u][i], dp[u][i - ]);
for(int p = head[u]; p; p = next[p]) {
int &v = to[p];
for(int i = ; i <= T - cost[p]; ++i) {
if(dp[u][i] == -) continue;
update_max(dp[v][i + cost[p]], dp[u][i] + val[v]);
}
if(--indeg[v] == ) que.push(v);
}
}
int ans = ;
mat[n][ed] = mat[st][ed];
for(int i = ; i <= n; ++i) if(T - mat[i][ed] >= )
update_max(ans, dp[i][T - mat[i][ed]]);
//printdp();
return ans;
} void printdp() {
for(int i = ; i < n; ++i) {
for(int j = ; j <= T; ++j) printf("%d ", dp[i][j]);
printf("\n");
}
} } G; struct Original {
void read() {
memset(mat, 0x3f, sizeof(mat));
for(int i = ; i < n; ++i) mat[i][i] = ;
int u, v, c;
for(int i = ; i < m; ++i) {
scanf("%d%d%d", &u, &v, &c);
update_min(mat[u][v], c);
update_min(mat[v][u], c);
}
} void floyd() {
for(int k = ; k < n; ++k)
for(int i = ; i < n; ++i)
for(int j = ; j < n; ++j) update_min(mat[i][j], mat[i][k] + mat[k][j]);
} bool make_G() {
floyd();
if(mat[st][ed] > T) return false;
G.init();
for(int i = ; i < n; ++i)
for(int j = ; j < n; ++j)
if(val[i] < val[j]) G.add_edge(i, j, mat[i][j] + vis_c[j]);
for(int i = ; i < n; ++i)
G.add_edge(n, i, mat[st][i] + vis_c[i]);
return true;
}
} O; int main() {
int W;
scanf("%d", &W);
for(int w = ; w <= W; ++w) {
scanf("%d%d%d%d%d", &n, &m, &T, &st, &ed);
for(int i = ; i < n; ++i) scanf("%d", &vis_c[i]);
for(int i = ; i < n; ++i) scanf("%d", &val[i]);
O.read();
O.make_G();
printf("Case #%d:\n%d\n", w, G.solve());
}
}
HDU 4571 Travel in time(最短路径+DP)(2013 ACM-ICPC长沙赛区全国邀请赛)的更多相关文章
- HDU 4568 Hunter(最短路径+DP)(2013 ACM-ICPC长沙赛区全国邀请赛)
Problem Description One day, a hunter named James went to a mysterious area to find the treasures. J ...
- HDU 4571 Travel in time ★(2013 ACM/ICPC长沙邀请赛)
[题意]给定N个点,每个点有一个停留所需的时间Ci,和停留能够获得的满意度Si,有M条边,每条边代表着两个点走动所需的时间ti,现在问在规定的T时间内从指定的一点S到E能够获得的最大的满意度是多少?要 ...
- HDU 4573 Throw the Stones(动态三维凸包)(2013 ACM-ICPC长沙赛区全国邀请赛)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4573 Problem Description Remember our childhood? A fe ...
- HDU 4569 Special equations(枚举+数论)(2013 ACM-ICPC长沙赛区全国邀请赛)
Problem Description Let f(x) = anxn +...+ a1x +a0, in which ai (0 <= i <= n) are all known int ...
- HDU 4565 So Easy!(数学+矩阵快速幂)(2013 ACM-ICPC长沙赛区全国邀请赛)
Problem Description A sequence Sn is defined as:Where a, b, n, m are positive integers.┌x┐is the cei ...
- 2013 ACM/ICPC 长沙网络赛J题
题意:一个数列,给出这个数列中的某些位置的数,给出所有相邻的三个数字的和,数列头和尾处给出相邻两个数字的和.有若干次询问,每次问某一位置的数字的最大值. 分析:设数列为a1-an.首先通过相邻三个数字 ...
- 2013 ACM-ICPC长沙赛区全国邀请赛——Bottles Arrangement
这题当时竟然没看啊…… 找规律:求和m+m+m-1+m-1+……前n项 ;}
- 2013 ACM-ICPC长沙赛区全国邀请赛—Special equations
……但是没仔细看,直接跳过了 这题直接枚举就可以过了 ;}
- 2013 ACM-ICPC长沙赛区全国邀请赛——A So Easy!
这题在比赛的时候不知道怎么做,后来看了别人的解题报告,才知道公式sn=(a+sqrt(b))^n+(a-sqrt(b))^n; 具体推导 #include<iostream> #inclu ...
随机推荐
- papers-06-02
午睡被同事吵醒,只好干活.看到微信公众号有一篇文章说老朋友呢,点进去发现原来相关的工作好多,而且好新好细致. 微信的文章可以见这里: 探究最陌生的老朋友Softmax 里面的几篇文章可以看看. Lar ...
- 关于ProjectServer定制化项目中心页面
ProjectServer界面很多客户接受不了,随便用户可以根据自己需要展示页面,但大多数国内用户喜欢确定的样式,我就是要这样的页面,不要个人定制. 那只有自己再做一个项目中心的webpart嵌入,对 ...
- html基础用法(下)
设计表格: <html> <head> <title>表格</title> <meta charset="utf-8" /&g ...
- Angularjs基础(七)
AngularJS表单 AngularJS表单时输入控件的集合HTML控件 一下HTML input 元素被称为HTML 控件: input 元素 select元素 button元素 textarea ...
- POST和GET请求区别
最新博客站点:欢迎来访 1. 请求长度的限制 在HTTP协议中,从未规定GET/POST的请求长度限制,对于GET,对url的限制来源于浏览器或web服务器,浏览器和服务器限制了url的长度.因此,在 ...
- 关系型数据库设计——E-R图
一.数据管理技术的三个发展阶段: 1)人工管理阶段(20世纪50年代中期) 特点:数据不保存:应用程序管理数据:数据不共享:数据没有独立性: 2)文件系统阶段(20世纪50年代后—60年代)特点:数据 ...
- javascript--鼠标拖拽窗口案例(鼠标按下,在鼠标移动过程中,盒子跟着一起移动,鼠标松开,盒子停止移动)
界面如图所示: 要求:在“信息注册”栏,按下鼠标,然后鼠标在页面移动,在鼠标移动过程中,该窗口跟着鼠标移动,当鼠标松开的时候,窗口停止移动.点击“关闭”,该窗口隐藏. 实现思路: 1.页面结构分析:一 ...
- jquery图片滚动animate.css
@charset "UTF-8"; /*!Animate.css - http://daneden.me/animateLicensed under the MIT license ...
- red hat 7 启动过程(EFI)
不同版本的Linux系统的启动过程在某些地方是不一样的,现在先来介绍一下red hat 7 的启动过程(EFI). (加电→图形登录界面) 接通电源 按下电源键 EFI固件启动 初始化硬件 从EFI启 ...
- python2.7入门---变量类型&案例
这篇文章呢,主要是用来记录python中的变量类型学习内容的.接下来就来看一下变量类型,那么什么是变量呢.变量存储在内存中的值.这就意味着在创建变量时会在内存中开辟一个空间.基于变量的数据类型,解 ...