Problem Description
  Bob gets tired of playing games, leaves Alice, and travels to Changsha alone. Yuelu Mountain, Orange Island, Window of the World, the Provincial Museum etc...are scenic spots Bob wants to visit. However, his time is very limited, he can’t visit them all. 
  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.
 
Input
  The first line is an integer W, which is the number of testing cases, and the W sets of data are following.
  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)
 
Output
  Output case number in the first line (formatted as the sample output).
  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).
 
题目大意:有n个点m条无向边,每个点有一个权值和一个花费,每条边有一个花费。现在要从S走到E,允许的最大花费为T。经过一个点的时候可以获得它的权值,但同时也要经受那个点的花费,但每次获得的点权要比上一次或者的点券要大。每个点每条边都可以重复走。问从S走到E能获得的最大点权是多少。
思路:搜素超时无误>_<,正解为DP。先作一次floyd求出每个点之间的距离(因为要用到的点点间距太多了floyd正合适,虽说边少可以用SPFA很快,不过n只有100随便啦),然后重新建一个图,从点权小的点 i 到点权大的点 j 之间连一条边,花费为从 i 到 j 的最短路径。得到的图是一个DAG可以用来做DP。DP[i][j]表示到达第i个点并参观,总花费为j,能获得的最大点权,按拓扑结构的顺序来做DP即可。答案为max{DP[i][j - mat[i][E]]}(可以认为我们呆在一个点不动直到做下一个动作,也就是呆着直到要不够时间到终点了)
PS:有重边要注意(原来不说就是有重边啊……)
PS2:记得输出那个Case啊我就忘了……
PS3:细节看代码,要注意不能到达终点的情况和能到终点权值却为0的情况。
PS4:为了方便做DP我加入了一个附加源点←_←
PS5:同一份题有两条最短路+DP大丈夫?虽说用的最短路和DP都不一样……
 
代码(843MS):
 #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长沙赛区全国邀请赛)的更多相关文章

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

  2. HDU 4571 Travel in time ★(2013 ACM/ICPC长沙邀请赛)

    [题意]给定N个点,每个点有一个停留所需的时间Ci,和停留能够获得的满意度Si,有M条边,每条边代表着两个点走动所需的时间ti,现在问在规定的T时间内从指定的一点S到E能够获得的最大的满意度是多少?要 ...

  3. HDU 4573 Throw the Stones(动态三维凸包)(2013 ACM-ICPC长沙赛区全国邀请赛)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4573 Problem Description Remember our childhood? A fe ...

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

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

  6. 2013 ACM/ICPC 长沙网络赛J题

    题意:一个数列,给出这个数列中的某些位置的数,给出所有相邻的三个数字的和,数列头和尾处给出相邻两个数字的和.有若干次询问,每次问某一位置的数字的最大值. 分析:设数列为a1-an.首先通过相邻三个数字 ...

  7. 2013 ACM-ICPC长沙赛区全国邀请赛——Bottles Arrangement

    这题当时竟然没看啊…… 找规律:求和m+m+m-1+m-1+……前n项 ;}

  8. 2013 ACM-ICPC长沙赛区全国邀请赛—Special equations

    ……但是没仔细看,直接跳过了 这题直接枚举就可以过了 ;}

  9. 2013 ACM-ICPC长沙赛区全国邀请赛——A So Easy!

    这题在比赛的时候不知道怎么做,后来看了别人的解题报告,才知道公式sn=(a+sqrt(b))^n+(a-sqrt(b))^n; 具体推导 #include<iostream> #inclu ...

随机推荐

  1. papers-06-02

    午睡被同事吵醒,只好干活.看到微信公众号有一篇文章说老朋友呢,点进去发现原来相关的工作好多,而且好新好细致. 微信的文章可以见这里: 探究最陌生的老朋友Softmax 里面的几篇文章可以看看. Lar ...

  2. 关于ProjectServer定制化项目中心页面

    ProjectServer界面很多客户接受不了,随便用户可以根据自己需要展示页面,但大多数国内用户喜欢确定的样式,我就是要这样的页面,不要个人定制. 那只有自己再做一个项目中心的webpart嵌入,对 ...

  3. html基础用法(下)

    设计表格: <html> <head> <title>表格</title> <meta charset="utf-8" /&g ...

  4. Angularjs基础(七)

    AngularJS表单 AngularJS表单时输入控件的集合HTML控件 一下HTML input 元素被称为HTML 控件: input 元素 select元素 button元素 textarea ...

  5. POST和GET请求区别

    最新博客站点:欢迎来访 1. 请求长度的限制 在HTTP协议中,从未规定GET/POST的请求长度限制,对于GET,对url的限制来源于浏览器或web服务器,浏览器和服务器限制了url的长度.因此,在 ...

  6. 关系型数据库设计——E-R图

    一.数据管理技术的三个发展阶段: 1)人工管理阶段(20世纪50年代中期) 特点:数据不保存:应用程序管理数据:数据不共享:数据没有独立性: 2)文件系统阶段(20世纪50年代后—60年代)特点:数据 ...

  7. javascript--鼠标拖拽窗口案例(鼠标按下,在鼠标移动过程中,盒子跟着一起移动,鼠标松开,盒子停止移动)

    界面如图所示: 要求:在“信息注册”栏,按下鼠标,然后鼠标在页面移动,在鼠标移动过程中,该窗口跟着鼠标移动,当鼠标松开的时候,窗口停止移动.点击“关闭”,该窗口隐藏. 实现思路: 1.页面结构分析:一 ...

  8. jquery图片滚动animate.css

    @charset "UTF-8"; /*!Animate.css - http://daneden.me/animateLicensed under the MIT license ...

  9. red hat 7 启动过程(EFI)

    不同版本的Linux系统的启动过程在某些地方是不一样的,现在先来介绍一下red hat 7 的启动过程(EFI). (加电→图形登录界面) 接通电源 按下电源键 EFI固件启动 初始化硬件 从EFI启 ...

  10. python2.7入门---变量类型&案例

      这篇文章呢,主要是用来记录python中的变量类型学习内容的.接下来就来看一下变量类型,那么什么是变量呢.变量存储在内存中的值.这就意味着在创建变量时会在内存中开辟一个空间.基于变量的数据类型,解 ...