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 ...
随机推荐
- 前端DOM知识点
DOM即文档对象模型(Document Object Model,DOM)是一种用于HTML和XML文档的编程接口.它给文档提供了一种结构化的表示方法,可以改变文档的内容和呈现方式.DOM把网页和脚本 ...
- 固定导航栏demo
代码如下 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF- ...
- oracle client安装与配置
(一)安装Oracle client 环境:windows7 64-bit.oracle client 64-bit (1)解压client安装包 (2)双击setup.exe,选择管理员,一直nex ...
- 核心动画(UIView封装动画)-转
一.UIView动画(首尾) 1.简单说明 UIKit直接将动画集成到UIView类中,当内部的一些属性发生改变时,UIView将为这些改变提供动画支持. 执行动画所需要的工作由UIView类自动完成 ...
- jwplayer 参数记录
jwplayer().getPosition()://播放了多少秒 jwplayer('playerdiv').play(); || jwplayer(0).play(true/false); // ...
- chromium之tracked
//------------------------------------------------------------------------------ // Tracked is the b ...
- tomcat端口占用后的解决办法【亲测有效】
https://www.cnblogs.com/zhangtan/p/5856573.html 检测正在使用的端口 这里就以win7为例进行讲解. 首先打开cmd,打开的方法很简单,在开始菜单中直 ...
- JavaScript--Dom操作元素的样式
在前端开发中,有时候需要动态修改的网页元素的样式,这里将使用JS动态修改元素样式的方法做个小结: 网页结构: 按钮: 标签:input 类型:button id:btn ...
- background兼容IE9以下版本
.box { width:100%; height:80%; background: url('img/nav_bg.png') no-repeat; backgrou ...
- React学习(1)—— 基础项目搭建以及环境配置
首先,我们需要安装node.js,直接搜索并在官网下载安装包. node.js官网:https://nodejs.org/en/ 现在我们成功安装了node和npm,然后我们来用npm创建新的项目,首 ...