uva 1025
紫皮书 非原创……
某城市的地铁是线性的有n个车站从左到右编号为1-n,有M1辆地铁从第一站出发,有M2辆车从最后一站出发,mario从第一站出发,目的是在时刻T会见车站n的一个朋友(间谍)。在车站等车容易被抓,所以尽量让其在车站的时间尽量短,mario能完成方向不同地铁的换乘
dp[i][j]表示i时刻j站最少还要等多长时间,边界dp[T][n] = 0;其他dp[T][i] 为正无穷
则有三种决策
1.等一分钟
2.搭乘左开的车
3.搭乘右开的车
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <stack>
#include <cctype>
#include <string>
#include <queue>
#include <map>
#include <set> using namespace std; const int INF = 0xffffff;
const double ESP = 10e-;
const double Pi = * atan(1.0);
const int MAXN = + ;
const long long mod = ;
const int dr[] = {,,-,,-,,-,};
const int dc[] = {,,,-,,-,-,};
typedef long long LL; LL gac(LL a,LL b){
return b?gac(b,a%b):a;
} int dp[][MAXN];
int n,T;
int t[MAXN];
int M1,M2;
int d[MAXN];
int e[MAXN];
bool has_train[][MAXN][]; int main(){
#ifndef ONLINE_JUDGE
freopen("input.in","r",stdin);
// freopen("output.txt","w",stdout);
#endif
int cas = ;
while(~scanf("%d",&n) && n){
scanf("%d",&T);
for(int i = ;i <= n;i++){
scanf("%d",&t[i]);
}
t[] = ;
t[n+] = ;
memset(has_train,,sizeof(has_train));
scanf("%d",&M1);
for(int i = ;i <= M1;i++){
scanf("%d",&d[i]);
int sum = d[i];
for(int j = ;j <= n;j++){
sum += t[j];
has_train[sum][j][] = ;
}
}
scanf("%d",&M2);
for(int i = ;i <= M2;i++){
scanf("%d",&e[i]);
int sum = e[i];
for(int j = n;j > ;j--){
sum += t[j+];
has_train[sum][j][] = ;
}
}
for(int i = ;i < n;i++){
dp[T][i] = INF;
}
dp[T][n] = ;
for(int i = T-;i > -;i--){
for(int j = ;j <= n;j++){
dp[i][j] = dp[i+][j] + ;//等待下一个单位
if(j < n && has_train[i][j][] && i + t[j+] <= T){ // 从左到右有可以搭乘的车
dp[i][j] = min(dp[i][j],dp[i+ t[j+]][j+]);
}
if(j > && has_train[i][j][] && i + t[j] <= T){//从右到左有可以搭乘的车
dp[i][j] = min(dp[i][j],dp[i+t[j] ][j-]);
}
}
}
printf("Case Number %d: ",cas++);
if(dp[][] >= INF){
printf("impossible\n");
}
else{
printf("%d\n",dp[][]);
}
}
return ;
}
uva 1025的更多相关文章
- UVA - 1025 A Spy in the Metro[DP DAG]
UVA - 1025 A Spy in the Metro Secret agent Maria was sent to Algorithms City to carry out an especia ...
- uva 1025 A Spy in the Metro 解题报告
A Spy in the Metro Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug Secr ...
- UVA 1025 -- A Spy in the Metro (DP)
UVA 1025 -- A Spy in the Metro 题意: 一个间谍要从第一个车站到第n个车站去会见另一个,在是期间有n个车站,有来回的车站,让你在时间T内时到达n,并且等车时间最短, ...
- uva 1025,城市的间谍
题目链接:https://uva.onlinejudge.org/external/10/1025.pdf 题意: 地铁是线性的,有n个站,编号(1~n),M1辆从左至右的车,和M2辆从右至左的车,发 ...
- 【uva 1025】A Spy in the Metro
[题目链接]:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- UVa 1025 A Spy in the Metro(动态规划)
传送门 Description Secret agent Maria was sent to Algorithms City to carry out an especially dangerous ...
- UVa 1025 A Spy in the Metro
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35913 预处理出每个时间.每个车站是否有火车 为了方便判断是否可行,倒推处理 ...
- UVa 1025 (动态规划) A Spy in the Metro
题意: 有线性的n个车站,从左到右编号分别为1~n.有M1辆车从第一站开始向右开,有M2辆车从第二站开始向左开.在0时刻主人公从第1站出发,要在T时刻回见车站n 的一个间谍(忽略主人公的换乘时间).输 ...
- DAG的动态规划 (UVA 1025 A Spy in the Metro)
第一遍,刘汝佳提示+题解:回头再看!!! POINT: dp[time][sta]; 在time时刻在车站sta还需要最少等待多长时间: 终点的状态很确定必然是的 dp[T][N] = 0 ---即在 ...
随机推荐
- DDL\DML\DCL\DQL
[DML] DML = Data Manipulation Language,数据操纵语言,命令使用户能够查询数据库以及操作已有数据库中的数据的计算机语言.具体是指是UPDATE更新.INSERT插入 ...
- ZOJ 2972 Hurdles of 110m 【DP 背包】
一共有N段过程,每段过程里可以选择 快速跑. 匀速跑 和 慢速跑 对于快速跑会消耗F1 的能量, 慢速跑会集聚F2的能量 选手一开始有M的能量,即能量上限 求通过全程的最短时间 定义DP[i][j] ...
- Git 配置editor编辑器
Git 配置editor编辑器 在ubuntu系统下,Git默认的编辑器是命令行,学名叫V什么的,使用起来诸多不便 在编辑提交日志的时候,用的比较多. 可以选择unbuntu默认的文档编辑器作为git ...
- csu1306: Manor
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1306 解题思路:唬人的水题,只要按照他的意思打,就能过,不过,数组最好开大点.用到优先队列,也可以 ...
- Spring连接MySQL、Oracle和SQL Server
其中applicationContext.xml的配置如下: <?xml version="1.0" encoding="UTF-8"?> < ...
- (csdn高校俱乐部编程挑战)2的补码
题目详情 在计算机中,整数是以2的补码的形式给出的. 给出整数A和B,如果计算机是32位机.求从A到B之间的全部二进制数中,一共用了多少个1. 输入格式: 多组数据,每组数据一行,由两个整数A,B, ...
- CentOS 如何安装git server + Gitolite 【配置不成功需要再测试2015-8-20】
安装git 关于安装git 可以参考 http://gitolite.com/gitolite/install.html 里面有官方的介绍 1. Git 的工作需要调用 curl,zlib,open ...
- 01-Foundation简介、NSObject、copy、NSString
目录: 一.Foundation常用类 二.Foundation简介 三.NSObject 四.NSString 回到顶部 一.Foundation常用类 1 NSObject.NSString.NS ...
- android switch语句case expressions must be constant expressions
在项目中遇到这样的Exception:case expressions must be constant expressions public class StandingCityActivity e ...
- 使用jQuery的attr方法来修改onclick值
这篇文章主要介绍了通过jQuery的attr修改onclick值的解决方法 ,需要的朋友可以参考下 var js = "alert('B:' + this.id); return false ...