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 ...
随机推荐
- SQL Server笔记——sql语句创建数据库
MS SQLServer的每个数据库包含: 1个主数据文件(.mdf)必须. 1个事务日志文件(.ldf)必须. 可以包含: 任意多个次要数据文件(.ndf) 多个事务日志文件 CREATE DATA ...
- UICollectionViewCell「居左显示」
UICollectionViewCell「居左显示」 准备: 1.UICollectionView Left Aligned Layout 一款UICollectionView居左显示的约束点击下载_ ...
- Golang学习笔记(一)
一段基础的go语言代码解析 package main import "fmt" func main(){ fmt.Println("hello golang") ...
- ABAP术语-Business Scenario
Business Scenario 原文:http://www.cnblogs.com/qiangsheng/archive/2008/01/12/1035980.html End-to-end co ...
- This system is registered to Red Hat Subscription Management, but is not receiving updates. You can use subscription-manager to assign subscriptions.
Wrong date and time, reset the date and time in the system properly. It may also happen that system ...
- android Service服务简介(一)
作为android的四大组件之一,服务也少不了很多重要的知识点.下面我们从最基本的开始学习. 1.1服务的创建 首先创建一个ServiceTest类继承Service.我们会重写onCreate(), ...
- BC追踪
项目又要开始改造了,记录一下改造过程中碰到的坑和解决思路,避免以后回头看看自己的笔记都不知道写了什么. (一)敏感信息混淆 (二)活用ComponentScan (三)Swagger配置多项目共用 ( ...
- 【tp5.1】composer安装PHPExcel以及导入\导出Excel
一.安装PHPExcel 1.下载:PHPExcel https://github.com/PHPOffice/PHPExcel 2.解压后:Classes文件夹改名为PHPExcel 3.把文件夹 ...
- Promise 的基础用法
Promise 的含义 Promise 是异步编程的一种解决方案,比传统的解决方案–回调函数和事件--更合理和更强大.它由社区最早提出和实现,ES6将其写进了语言标准,统一了语法,原生提供了Promi ...
- scala成长之路(2)对象和类
scala提供了一种特殊的定义单例的方法:object关键字 scala> object Shabi{ | val age = 0 | val name = "shabi" ...